# This code and the accompanying RData file reproduce all the results from "Evidence Can Change Partisan Minds but Less So in Hostile Contexts," following the order presented in the main text and appendices.


# working directory ----
setwd("YOUR WD") # change this to your WD where `aca_bjps.RData` is saved.

# libraries ----
library(tidyverse)
library(car)
library(haven)
library(sandwich)
library(labelled)
library(stargazer)
library(estimatr)
library(prediction)
library(ggplot2)
library(multcomp)
library(devtools)
library(patchwork)
library(broom)
library(psych)
library(xtable)
library(sjmisc)
library(survey)
library(moments)
library(diptest)
library(janitor)
library(conflicted)
library(mlogit)
library(car)
library(nnet)
library(lmtest)
library(lubridate)
library(psych)
library(rsample)

conflict_prefer("select", "dplyr")
conflict_prefer("recode", "dplyr")
conflict_prefer("filter", "dplyr")


# DATA ----


# 
# w1<-to_labelled(read_dta("w1.dta")) # commenting out procedure to create Rdata file
# w2<-to_labelled(read_dta("w2.dta"))
# w3<-to_labelled(read_dta("w3.dta"))
# w4<-to_labelled(read_dta("w4.dta"))
# w1$matchedid<-w1$WorkerId
# 
# aca<-w1 %>%
#   full_join (w2, by = "matchedid")%>%
#   full_join (w3, by = "matchedid")%>%
#   full_join (w4, by = "matchedid")
# 
# # selecting necessary variables
# aca<-aca%>%
#   select(.,treat,q6_5:q6_8,q2_1:q2_4, q2_8:q2_11, q3_2:q3_5, q6_9, q6_10, q4_4, q5_1, q5_2,
#          a15_3, a15_4, a15_5, a20_1,
#          a3_2_1: a3_2_18, a12_1:a12_4, a12_8:a12_11, a14_4:a14_6, a18_1: a18_4, a19_3, a18_5, a18_7,
#                 c2_2:c2_8, c3_1:c3_3,c5_2, c5_3,
#                 f4:f13,f20, f21,
#                 a1_1, c1_1, f1) # survey question numbers in each wave start with: Wave 1 = q; Wave 2 = a; Wave 3 = c; Wave 4 = f
# 
# rm(w1,w2,w3,w4)
# 
# 
# aca18<-to_labelled(read_dta("aca 2018.dta"))%>%
#   dplyr::select(., treat, priming, q2_2:q2_4, q2_6: q2_9, q15_1:q15_7, q16_1: q16_4, q5_1: q5_5, q2_10,
#                 q17_1_1, q17_1_2, q6_2_1:q6_2_18, q18_7, q18_8)
# 
# econ<-read_dta("economy combined.dta")%>%
#   select(cond, q23_1, q23_2, a8_2, a8_3, q3_1, q2_1, q2_2, q2_3, q2_4, q17_1, q17_2, q17_3, q17_4, q20_1, a3_1, a3_2, a3_3, a3_4, a6_1)
# 
# 
# 
# 
# anes<-read_dta("anes2016.dta")
# anes.var<-lookfor(anes,"")
# anes18<-read_sav("anes_pilot_2018.sav")
# anes18.var<-lookfor(anes18,"")
# anes12<-read_dta("anes_timeseries_2012.dta")
# anes20<-read_sav("anes_timeseries_2020_spss_20220210.sav")
# anes12.var<-lookfor(anes12,"")
# anes20.var<-lookfor(anes20,"")
# 
# 
# cc12<-read_dta("cc12.dta")
# cc13<-read_dta("cc13.dta")
# cc14<-read_dta("cc14.dta")
# cc15<-read_dta("cc15.dta")
# cc16<-read_dta("cc16.dta")
# cc17<-read_dta("cc17.dta")
# cc18<-read_dta("cc18.dta")
# cc19<-read_dta("cc19.dta")
# cc20<-read_dta("cc20.dta")
# 
# cc12.var<-lookfor(cc12, details = "none")
# cc13.var<-lookfor(cc13, details = "none")
# cc14.var<-lookfor(cc14, details = "none")
# cc15.var<-lookfor(cc15, details = "none")
# cc16.var<-lookfor(cc16, details = "none")
# cc17.var<-lookfor(cc17, details = "none")
# cc18.var<-lookfor(cc18, details = "none")
# cc19.var<-lookfor(cc19, details = "none")
# cc20.var<-lookfor(cc20, details = "none")
# 
# save.image("aca_bjps.RData")

load("aca_bjps.RData")

  
  ## VARIABLE CODING ----
  # STUDY 1 Coding ----
  
  
  aca$wave2<-case_when(
    aca$a1_1==1~1,
    is.na(aca$a1_1)~0
  )
  
  aca$wave3<-case_when(
    aca$c1_1==1~1,
    is.na(aca$c1_1)~0
  )
  
  aca$wave4<-case_when(
    aca$f1==1~1,
    is.na(aca$f1)~0
  )
  
  
  aca$cond<-case_when(
    aca$treat==1 ~ "4", # strong pro
    aca$treat==2 ~ "3", # weak pro
    aca$treat==3 ~ "1", # strong con
    aca$treat==4 ~ "2", # weak con
    aca$treat==5 ~ "0", # placebo
  )%>%as.factor() # conditions 
  
  aca$pid7<-case_when(
    aca$q6_6==1 ~ 6,
    aca$q6_6==2 ~ 5,
    aca$q6_8==1 ~ 4,
    aca$q6_8==2 ~ 2,
    aca$q6_8==3 ~ 3,
    aca$q6_7==1 ~ 0,
    aca$q6_7==2 ~ 1
  )
  aca$pid<-aca$pid7/6
  
  aca$dem<-case_when(
    aca$pid>.5~1,
    aca$pid<.5~0
  )
  
  aca$rep<-1-aca$dem
  
  
  aca$w1aca1<-case_when(
    aca$q2_2==1 ~6,
    aca$q2_2==2 ~5,
    aca$q2_3==1 ~0,
    aca$q2_3==2 ~1,
    aca$q2_4==1 ~ 4,
    aca$q2_4==2 ~ 2,
    aca$q2_4==3 ~ 3
  )
  
  aca$w1aca1<-aca$w1aca1/6
  
  
  # Define the function to recode the values
  recode15 <- function(x) {
    dplyr::case_when(
      x == 1 ~ 0,
      x == 2 ~ 0.25,
      x == 3 ~ 0.5,
      x == 4 ~ 0.75,
      x == 5 ~ 1,
      x == 6 ~ 0.5,
      TRUE ~ NA_real_
    )
  }
  
  recode51 <- function(x) {
    dplyr::case_when(
      x == 1 ~ 1,
      x == 2 ~ 0.75,
      x == 3 ~ 0.5,
      x == 4 ~ 0.25,
      x == 5 ~ 0,
      x == 6 ~ 0.5,
      TRUE ~ NA_real_
    )
  }
  
  aca <- aca %>%
    mutate(w1aca2 = recode15(q2_8),
           w1aca3 = recode51(q2_9),
           w1aca4 = recode51(q2_10),
           w1aca5 = recode51(q2_11))
  
    
  
  aca <- aca %>%
    mutate(w1cost1 = recode51(q4_4))
  aca$w1cost2 <- (7 - aca$q5_1) / 6
  aca$w1cost3 <- (aca$q5_2 - 1) / 6
  aca$w1cost2 <- ifelse(aca$q5_1 == 10, .5, aca$w1cost2)
  aca$w1cost3 <- ifelse(aca$q5_2 == 10, .5, aca$w1cost3)
  
  dplyr::select(aca, w1cost1, w1cost2, w1cost3)%>%psych::alpha()
  
  aca <- aca %>%
    mutate(w1accessimportant = recode51(q3_2),
           w1qualityimportant = recode51(q3_3),
           w1governmentimportant = recode51(q3_4),
           w1costimportant = recode51(q3_5))
  
  
  aca<-aca%>%
    mutate(w1obama = recode51(q6_9),
           w1obamahc = recode51(q6_10),
           obama = recode51(a15_4),
           obamahc = recode51(a15_5)
    )
  
  
  
  
  aca$aca1<-case_when(
    aca$a12_2==1 ~6,
    aca$a12_2==2 ~5,
    aca$a12_3==1 ~0,
    aca$a12_3==2 ~1,
    aca$a12_4==1 ~ 4,
    aca$a12_4==2 ~ 2,
    aca$a12_4==3 ~ 3
  )
  aca$aca1<-aca$aca1/6
  
  
  aca <- aca %>%
    mutate(aca2 = recode15(a12_8),
           aca3 = recode51(a12_9),
           aca4 = recode51(a12_10),
           aca5 = recode51(a12_11))
  aca%>%dplyr::select(., aca1:aca5)%>%psych::alpha()
  
  
  
  
  aca <- aca %>%
    mutate(cost1 = recode51(a14_4))
  aca$cost2 <- (7 - aca$a14_5) / 6
  aca$cost3 <- (aca$a14_6 - 1) / 6
  aca$cost2 <- ifelse(aca$a14_5 == 10, .5, aca$cost2)
  aca$cost3 <- ifelse(aca$a14_6 == 10, .5, aca$cost3)
  
  aca%>%dplyr::select(., cost1:cost3)%>%psych::alpha()
  
  
  aca$w3aca1<-case_when(
    aca$c2_2==1 ~6,
    aca$c2_2==2 ~5,
    aca$c2_3==1 ~0,
    aca$c2_3==2 ~1,
    aca$c2_4==1 ~ 4,
    aca$c2_4==2 ~ 2,
    aca$c2_4==3 ~ 3
  )
  
  
  
  aca$w3aca1<-aca$w3aca1/6
  aca <- aca %>%
    mutate(w3aca2 = recode15(c2_5),
           w3aca3 = recode51(c2_6),
           w3aca4 = recode51(c2_7),
           w3aca5 = recode51(c2_8))
  
  aca <- aca %>%
    mutate(w3cost1 = recode51(c3_1))
  
  aca$w3cost2 <- (7 - aca$c3_2) / 6
  aca$w3cost3 <- (aca$c3_3 - 1) / 6
  aca$w3cost2 <- ifelse(aca$c3_2 == 10, .5, aca$w3cost2)
  aca$w3cost3 <- ifelse(aca$c3_3 == 10, .5, aca$w3cost3)
  
  aca$w4aca1<-case_when(
    aca$f4==1 ~6,
    aca$f4==2 ~5,
    aca$f5==1 ~0,
    aca$f5==2 ~1,
    aca$f6==1 ~ 4,
    aca$f6==2 ~ 2,
    aca$f6==3 ~ 3
  )
  
  aca$w4aca1<-aca$w4aca1/6
  
  aca <- aca %>%
    mutate(w4aca2 = recode15(f7),
           w4aca3 = recode51(f8),
           w4aca4 = recode51(f9),
           w4aca5 = recode51(f10))
  
  aca <- aca %>%
    mutate(w4cost1 = recode51(f11))
  aca$w4cost2 <- (7 - aca$f12) / 6
  aca$w4cost3 <- (aca$f13 - 1) / 6
  aca$w4cost2 <- ifelse(aca$f12 == 10, .5, aca$w4cost2)
  aca$w4cost3 <- ifelse(aca$f13 == 10, .5, aca$w4cost3)
  
  aca<-aca%>%
    mutate (w1aca = rowMeans(dplyr::select(., w1aca1:w1aca5), na.rm=T),
            w1cost = rowMeans(dplyr::select(., w1cost1:w1cost3), na.rm=T),
            aca = rowMeans(dplyr::select(., aca1:aca5), na.rm=T),
            cost = rowMeans(dplyr::select(., cost1:cost3), na.rm=T),
            w3aca = rowMeans(dplyr::select(., w3aca1:w3aca5), na.rm=T),
            w3cost = rowMeans(dplyr::select(., w3cost1:w3cost3), na.rm=T),
            w4aca = rowMeans(dplyr::select(., w4aca1:w4aca5), na.rm=T),
            w4cost = rowMeans(dplyr::select(., w4cost1:w4cost3), na.rm=T)
            )
  
  
  
  aca$w2recall<-case_when(aca$cond=="1" & aca$a20_1==1 ~ 1,
                          aca$cond=="2" & aca$a20_1==2 ~ 1,
                          aca$cond=="3" & aca$a20_1==4 ~ 1,
                          aca$cond=="4" & aca$a20_1==3 ~ 1)
  
  
  
  aca$w2recall[is.na(aca$w2recall)&!is.na(aca$a20_1)&aca$cond!="0"]<-0    
  
  
  aca$w3recall<-case_when(aca$cond=="1" & aca$c5_3==1 ~ 1,
                          aca$cond=="2" & aca$c5_3==2 ~ 1,
                          aca$cond=="3" & aca$c5_3==4 ~ 1,
                          aca$cond=="4" & aca$c5_3==3 ~ 1)
  
  aca$w3recall[is.na(aca$w3recall)&!is.na(aca$c5_3)&aca$cond!="0"]<-0    
  
  
  aca$w3recall2<-case_when(aca$cond=="1" & aca$c5_2==2 ~ 1,
                           aca$cond=="2" & aca$c5_2==2 ~ 1,
                           aca$cond=="3" & aca$c5_2==1 ~ 1,
                           aca$cond=="4" & aca$c5_2==1 ~ 1)
  
  aca$w3recall2[is.na(aca$w3recall2)&!is.na(aca$c5_2)&aca$cond!="0"]<-0 
  
  
  aca$w4recall<-case_when(aca$cond=="1" & aca$f21==1 ~ 1,
                          aca$cond=="2" & aca$f21==2 ~ 1,
                          aca$cond=="3" & aca$f21==4 ~ 1,
                          aca$cond=="4" & aca$f21==3 ~ 1)
  
  aca$w4recall[is.na(aca$w4recall)&!is.na(aca$f21)&aca$cond!="0"]<-0    
  
  
  aca$w4recall2<-case_when(aca$cond=="1" & aca$f20==2 ~ 1,
                           aca$cond=="2" & aca$f20==2 ~ 1,
                           aca$cond=="3" & aca$f20==1 ~ 1,
                           aca$cond=="4" & aca$f20==1 ~ 1)
  
  aca$w4recall2[is.na(aca$w4recall2)&!is.na(aca$f20)&aca$cond!="0"]<-0 
  
  aca$congenial<-case_when(aca$dem==0 & (aca$cond=="1"|aca$cond=="2") ~ 1,
                           aca$dem==0 & (aca$cond=="3"|aca$cond=="4") ~ 0,
                           aca$dem==1 & (aca$cond=="1"|aca$cond=="2") ~ 0,
                           aca$dem==1 & (aca$cond=="3"|aca$cond=="4") ~ 1)
  
  aca$uncongenial<-1-aca$congenial
  
  aca$wgt2<-1*(aca$a3_2_16==1)*(aca$a3_2_10==1)*(aca$a3_2_18==1) ## attention check
  
  # demographics 
  aca<-aca%>%
    mutate(
      age = a18_4 -2,
      age2 = case_when(
        a18_4<=3 ~ 0, #"44 or younger",
        a18_4>=4 ~ 1, #"45 or older",
      ),
      age3 = case_when(
        a18_4<=2 ~ 0, #"25 or younger",
        a18_4>=3 & a18_4<=4 ~ 1, #"26 to 44",
        a18_4>=5 ~ 2 #"45 or older"
      ),
      female = a18_5-1,
      white = ifelse(a18_7==1, 1, 0),
      educ = case_when(
        a18_1 < 3 ~ 0,     #"high school",
        a18_1 == 3|a18_1==4 ~1,    # "some college"
        a18_1 > 4 ~ 2    # ba
      ),
      educ2 = case_when(
        a18_1 <=4 ~ 0,     
        a18_1 > 4 ~ 1    # ba
      ),
      income = case_when(
        a18_2 <4 ~ 0, #"50K-",
        a18_2 >=4 ~ 1 # "50K+",
      ),
      class = case_when(
        a18_3 <=2 ~ 0,
        a18_3 >=3 & a18_3 <=5 ~ 1
      ),
      insurance = 2-a19_3,
      support = 1*(w1aca>.5)
    )
  
  aca<-aca%>%
    mutate(
      str = case_when(
        pid7 == 0 | pid7 == 6 ~ 1,
        pid7 >=1 | pid7 <=5 ~ 0),
      pid3 = case_when(
        pid7 <=2 ~ 0, # rep
        pid7 ==3 ~ 1, # pure
        pid7 >=4 ~ 2)) #dem
  
  aca$age45 <- 1*(aca$age3 == 2)
  
  
  # STUDY 2 Coding ----
  
  aca18 <- aca18 %>%
    mutate(cond = recode(treat, `1` = 3, `2` = 4, `3` = 1, `4` = 2, `5` = 0)%>%factor(),
           cond2 = recode(treat, `1` = 2, `2` = 4, `3` = 1, `4` = 3, `5` = 0)%>%factor())
  
  
  
  aca18$pid7<-case_when(
    aca18$q2_2==1 ~ 6,
    aca18$q2_2==2 ~ 5,
    aca18$q2_4==1 ~ 4,
    aca18$q2_4==2 ~ 2,
    aca18$q2_4==3 ~ 3,
    aca18$q2_3==1 ~ 0,
    aca18$q2_3==2 ~ 1
  )
  aca18$pid<-aca18$pid7/6
  
  aca18$dem<-case_when(
    aca18$pid>.5~1,
    aca18$pid<.5~0
  )
  
  aca18$rep<-1-aca18$dem
  
  
  
  aca18$aca0<-case_when(
    aca18$q2_6==1~7-aca18$q2_7,
    aca18$q2_6==2~aca18$q2_8-1,
    aca18$q2_9==1~4,
    aca18$q2_9==2~2,
    aca18$q2_9==3~3
  )/6
  
  aca18$aca1<-case_when(
    aca18$q15_1==1~7-aca18$q15_2,
    aca18$q15_1==2~aca18$q15_3-1,
    aca18$q15_4==1~4,
    aca18$q15_4==2~2,
    aca18$q15_4==3~3
  )/6
  
  aca18$aca2<-case_when(
    aca18$q15_5<=5~(aca18$q15_5-1)/4,
    aca18$q15_5==6~0.5
  )
  
  aca18$aca3<-case_when(
    aca18$q15_6<=5~(5-aca18$q15_6)/4,
    aca18$q15_6==6~0.5
  )
  
  aca18$aca4<-case_when(
    aca18$q15_7<=5~(aca18$q15_7-1)/4,
    aca18$q15_7==6~0.5
  )
  
  
  aca18 <- aca18 %>%
    mutate(cost1 = recode(q16_1, `6` = 3),
           cost1 = (5 - cost1) / 4,
           cost2 = recode(q16_2, `6` = 3),
           cost2 = (5 - cost2) / 4,
           cost3 = recode(q16_3, `6` = 3),
           cost3 = (cost3 - 1) / 4,
           cost4 = recode(q16_4, `6` = 3),
           cost4 = (cost4 - 1) / 4)
  
  
  
  psych::alpha(dplyr::select(aca18,aca1,aca2,aca3,aca4))
  psych::alpha(dplyr::select(aca18,cost1,cost2,cost3,cost4))
  aca18$aca<-rowMeans(dplyr::select(aca18,aca1,aca2,aca3,aca4))
  aca18$cost<-rowMeans(dplyr::select(aca18,cost1,cost2,cost3,cost4))
  
  aca18$inparty<-case_when(aca18$dem==0 ~ aca18$q17_1_1,
                           aca18$dem==1 ~ aca18$q17_1_2)
  aca18$outparty<-case_when(aca18$dem==0 ~ aca18$q17_1_2,
                            aca18$dem==1 ~ aca18$q17_1_1)
  aca18$ap<-aca18$inparty-aca18$outparty
  
  
  aca18 <- aca18 %>%
    mutate(wgt = 1 * (q6_2_10 == 1) * (q6_2_16 == 1))
  
  aca18 <- aca18 %>%
    mutate(
      civil1 = recode(q18_7, `7` = 3),
      civil1 = (5 - civil1) / 4,
      civil2 = recode(q18_8, `6` = 3),
      civil2 = (5 - civil2) / 4,
      civil = (civil1+civil2)*0.5
    )
  
  
  
  
  # STUDY 2 Demo 
  
  
  aca18<-aca18%>%
    mutate(
      age = case_when(
        q5_1==1|q5_1==2 ~ 0, #"34 or younger",
        q5_1==2|q5_1==4 ~ 1,
        q5_1==6|q5_1==5 ~ 2 
      ),
      age2 = case_when(
        q5_1==1|q5_1==2 ~ 0, 
        q5_1>=3 ~ 1,
      ),
      age3 = case_when(
        q5_1==1 ~ 0, 
        q5_1>=2 & q5_1<=3 ~ 1, #"34 or younger",
        q5_1>=4 ~ 2, #"35 or older",
      ),
      female = q5_2-1,
      white = ifelse(q5_3==1, 1, 0),
      educ = case_when(
        q5_4 < 3 ~ 0,     #"high school",
        q5_4 == 3|q5_4==4 ~1,    # "some college"
        q5_4 > 4 ~ 2    # ba
      ),
      educ2 = case_when(
        q5_4 <=4 ~ 0,     
        q5_4 > 4 ~ 1    # ba
      ),
      income = case_when(
        q5_5 <6 ~ 0, #"50k-",
        q5_5 >=6 ~ 1 # "50k+",
      ),
      support = case_when(
        aca0>.5 ~1,
        aca0 <=.5 ~ 0
      ),
      str = case_when(
        pid7 == 0 | pid7==6 ~ 1,
        pid7 >0 & pid7<6 ~ 0
      ),
      trump = (5-q2_10)/4
    )
  
  
  val_labels(aca18$pid7) <- c(a=0, b=1, c=2, d=3, e=4, f=5, g=6)
  
  
  # ANES coding -----
  
  
  anes<-anes%>%
    mutate(
      age = case_when(
        V161267x>=1&V161267x<5 ~ 0, # "34 or younger",
        V161267x>=5&V161267x<9 ~1, # "35 to 54",
        V161267x>=9&V161267x<=13 ~ 2 #"55 or older"
      ),
      age2 = case_when(
        V161267>=18&V161267<34 ~ 0, # "34 or younger",
        V161267>=35&V161267<=90 ~1, # "35 +",
      ),
      age3 = case_when(
        V161267>=18&V161267<26 ~ 0, # "25 or younger",
        V161267>=26&V161267<45 ~ 1, # "35 or younger",
        V161267>=45&V161267<=90 ~2, # "55 +",
      ),
      female = case_when(
        V161342 == 1 ~ 0,
        V161342 == 2 ~ 1
      ),
      white = ifelse(V161310x==1, 1, 0),
      educ = case_when(
        V161270 >=1 & V161270 <=9 | V161270 == 90 ~ 0, # "high school",
        V161270 >= 10 & V161270 <=12 ~ 1, #"some college",
        V161270 >= 13 & V161270 <=16 ~ 2 # "ba",
      ),
      educ2 = case_when(
        V161270 >=1 & V161270 <=12 | V161270 == 90 ~ 0, # "no ba",
        V161270 >= 13 & V161270 <=16 ~ 1 # "ba",
      ),
      income = case_when(
        V161361x >=1 & V161361x <=14 ~ 0, #"50K-",
        V161361x >=15 & V161361x <=28 ~1 # "50K+",
      ),
      class = case_when(
        V161307 == 1 | V161307 == 2 ~ 0,
        V161307 == 3 | V161307 == 4 ~ 1
      ),
      insurance = ifelse(V161112 ==1 ,1, 0),
      pid7 = case_when( V161158x >0 ~ 7-V161158x),
      pid3 = case_when(
        pid7<=2 ~ 0,
        pid7==3~ 1,
        pid7>=4 ~ 2
      ),
      dem = case_when (
        V161158x >=1 & V161158x<=3 ~ 1,
        V161158x >=5 ~ 0
      ),
      str = case_when(
        V161158x ==1 | V161158x ==7 ~ 1,
        V161158x >=2 & V161158x <=6 ~ 0
      ),
      support = case_when(
        V161114x >=1 & V161114x <=3 ~ 1,
        V161114x >=4 ~ 0
      ),
      support.o = case_when(
        V161082x >=1 & V161082x <=2 ~ 1,
        V161082x >=3 ~ 0
      )
    )
  
  
  anes18<-anes18%>%
    mutate(
      age2 = case_when(
        birthyr <= 1983 ~ 1, # 35+
        birthyr > 1983 ~ 0
      ),
      age3 = case_when(
        birthyr >=1993 ~ 0,
        birthyr <= 1992 & birthyr >= 1974 ~ 1,
        birthyr <= 1973 ~ 2
      ),
      female = case_when(
        gender == 1 ~ 0,
        gender == 2 ~ 1
      ),
      white = ifelse(race==1, 1, 0),
      educ3 = case_when(
        educ>=1 & educ <=2  ~ 0, # "high school",
        educ>=3 & educ <=4 ~ 1, #"some college",
        educ>=5  ~ 2 # "ba",
      ),
      educ2 = case_when(
        educ>=1 & educ <=5  ~ 0,
        educ>=6  ~ 1 # "ba",
      ),
      income = case_when(
        faminc_new >=1 & faminc_new <=5 ~ 0, #"50k-",
        faminc_new >=6 & faminc_new <=16 ~1 # "50k+",
      ),
      pid7 = 7- pid7x, 
      dem = case_when (
        pid7x >=1 & pid7x<=3 ~ 1,
        pid7x >=5 ~ 0
      ),
      pid3 = case_when(
        pid7<=2 ~ 0,
        pid7==3~ 1,
        pid7>=4 ~ 2
      ),
      str = case_when(
        pid7x ==1 | pid7x ==7 ~ 1,
        pid7x >=2 & pid7x <=6 ~ 0
      ),
      support = case_when(
        acaapprove <=3 ~ 1,
        acaapprove >4 ~ 0
      ),
      support.t = case_when(
        apppres <= 3 ~ 1,
        apppres > 4 ~ 0
      )
    )
  
  anes12<-anes12%>%
    mutate(
      aca = ifelse(health_2010hcr_x> 0, (7-health_2010hcr_x)/6, NA),
      dem = case_when(pid_x>=1 & pid_x<=3 ~ 1, 
                      pid_x>=4 ~ 0),
      weights = weight_full,
      year = 2012
    )
  
  anes20<-anes20%>%
    mutate(
      aca = ifelse(V202328x> 0, (7-V202328x)/6, NA),
      dem = case_when(V201231x>=1 & V201231x<=3 ~ 1, 
                      V201231x>=4 ~ 0),
      weights = V200010b,
      year = 2020
    )
  
  anes<-anes%>%
    mutate(
      aca = ifelse(V161114x> 0, (7-V161114x)/6, NA),
      weights = V160101,
      year = 2016
    )
  
  anes18<-anes18%>%
    mutate(
      aca = ifelse(acaapprove> 0, (7-acaapprove)/6, NA),
      weights = weight_spss,
      year = 2018)
      
  
  
  # CCES coding ----
  
  cc12<-cc12%>%mutate(
    aca =  CC332G-1,
    dem = case_when (pid7<4 ~ 1, pid7 >4 & pid7 <8 ~ 0),
    weight = V103,
    year = 2012
  )
  
  cc13<-cc13%>%mutate(
    aca = CC332C-1,
    dem = case_when (pid7<4 ~ 1, pid7 >4 & pid7 <8 ~ 0),
    year = 2013
  )
  
  
  cc14<-cc14%>%mutate(
    aca = CC14_324_2-1,
    dem = case_when (pid7<4 ~ 1, pid7 >4 & pid7 <8 ~ 0),
    year = 2014
  )
  
  
  cc15<-cc15%>%mutate(
    aca = CC15_327A-1,
    dem = case_when (pid7<4 ~ 1, pid7 >4 & pid7 <8 ~ 0),
    year = 2015
  )
  
  cc16<-cc16%>%mutate(
    aca = CC16_351I-1,
    dem = case_when (pid7<4 ~ 1, pid7 >4 & pid7 <8 ~ 0),
    year = 2016,
    weight = commonweight
  )
  
  cc17<-cc17%>%mutate(
    aca = CC17_340A-1,
    dem = case_when (pid7<4 ~ 1, pid7 >4 & pid7 <8 ~ 0),
    year = 2017,
    weight = weights_common
  )
  
  cc18<-cc18%>%mutate(
    aca = CC18_327c-1,
    dem = case_when (pid7<4 ~ 1, pid7 >4 & pid7 <8 ~ 0),
    year = 2018,
    weight = commonweight
  )
  
  cc19<-cc19%>%mutate(
    aca = CC19_327d-1,
    dem = case_when (pid7<4 ~ 1, pid7 >4 & pid7 <8 ~ 0),
    year = 2019,
    weight = commonweight
  )
  
  cc20<-cc20%>%mutate(
    aca = CC20_327d-1,
    dem = case_when (pid7<4 ~ 1, pid7 >4 & pid7 <8 ~ 0),
    year = 2020,
    weight = commonweight
  )
  
  # Econ Study Coding ----
  
  econ<-econ%>%
    mutate(
      
      econ0 = case_when(q3_1 <=5 ~ (5-q3_1)/4,
                        q3_1 == 6 ~ .5),
      
      econ1 = case_when(q17_1 <=5 ~ (5-q17_1)/4,
                       q17_1 == 6 ~ .5),
      econ2 = case_when(q17_2 <=5 ~ (5-q17_2)/4,
                        q17_2 == 6 ~ .5),
      econ3 = case_when(q17_3 <=5 ~ (q17_3-1)/4,
                        q17_3 == 6 ~ .5),
      econ4 = case_when(q17_4 <=5 ~ (5-q17_4)/4,
                        q17_4 == 6 ~ .5),
      econ5 = case_when(q20_1 <=5 ~ (5-q20_1)/4,
                        q20_1 == 6 ~ .5),
      econ = (econ1+econ2+econ3+econ4+econ5)/5,
      
      w2econ1 = case_when(a3_1 <=5 ~ (5-a3_1)/4,
                          a3_1 == 6 ~ .5),
      w2econ2 = case_when(a3_2 <=5 ~ (5-a3_2)/4,
                          a3_2 == 6 ~ .5),
      w2econ3 = case_when(a3_3 <=5 ~ (a3_3-1)/4,
                          a3_3 == 6 ~ .5),
      w2econ4 = case_when(a3_4 <=5 ~ (5-a3_4)/4,
                          a3_4 == 6 ~ .5),
      w2econ5 = case_when(a6_1 <=5 ~ (5-a6_1)/4,
                          a6_1 == 6 ~ .5),
      w2econ = (w2econ1+w2econ2+w2econ3+w2econ4+w2econ5)/5,
      
      recall1 = case_when(
        cond==2&q23_1==1 ~ 1,
        cond==2&q23_1!=1 ~ 0,
        cond==3&q23_1==2 ~ 1,
        cond==3&q23_1!=2 ~ 0,
        cond==4&q23_1==1 ~ 1,
        cond==4&q23_1!=1 ~ 0,
        cond==5&q23_1==2 ~ 1,
        cond==5&q23_1!=2 ~ 0),
      recall2 = case_when(
        cond==2&q23_2==2 ~ 1,
        cond==2&q23_2!=2 ~ 0,
        cond==3&q23_2==4 ~ 1,
        cond==3&q23_2!=4 ~ 0,
        cond==4&q23_2==1 ~ 1,
        cond==4&q23_2!=1 ~ 0,
        cond==5&q23_2==3 ~ 1,
        cond==5&q23_2!=3 ~ 0),
      w2recall1 = case_when(
        cond==2&a8_2==1 ~ 1,
        cond==2&a8_2!=1 ~ 0,
        cond==3&a8_2==2 ~ 1,
        cond==3&a8_2!=2 ~ 0,
        cond==4&a8_2==1 ~ 1,
        cond==4&a8_2!=1 ~ 0,
        cond==5&a8_2==2 ~ 1,
        cond==5&a8_2!=2 ~ 0),
      w2recall2 = case_when(
        cond==2&a8_3==2 ~ 1,
        cond==2&a8_3!=2 ~ 0,
        cond==3&a8_3==4 ~ 1,
        cond==3&a8_3!=4 ~ 0,
        cond==4&a8_3==1 ~ 1,
        cond==4&a8_3!=1 ~ 0,
        cond==5&a8_3==3 ~ 1,
        cond==5&a8_3!=3 ~ 0),
      recall_change1 = w2recall1-recall1,
      recall_change2 = w2recall2-recall2,
      recall_change_all = recall_change1 + recall_change2,
      
      pid7 = case_when(
        q2_2 == 1 ~ 6,
        q2_2 == 2 ~ 5,
        q2_4 == 1 ~ 4,
        q2_4 == 3 ~ 3,
        q2_4 == 2 ~ 2,
        q2_3 == 1 ~ 0,
        q2_3 == 2 ~ 1
      ),
      dem = case_when(
        pid7 < 3 ~ 0,
        pid7 > 3 ~ 1
      ),
      #rearranging conditions
      c = case_when( #
        cond == 0 | cond == 1 ~ "0", #placebo + control
        cond == 3 ~ "1", # gdp weak
        cond == 5 ~ "2", # gdp strong 
        cond == 2 ~ "3", # equal weak
        cond == 4 ~ "4" # equal strong
      ),
      c2 = ifelse(c=="0","0","1"),
      pid = pid7/6
    )
  
  ## MAIN TEXT ##################
  
  # Figure 1 (study 1: treatment effects) #######
  
  ##treatment effect models on aca attitude
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca)))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))
  m3<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))
  
  ##treatment effect models on cost belief
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca)))
  m5<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))
  m6<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))
  
  
  
  ##combining regression estimates into dataframes
  tcost<-bind_rows(all=m4[2:5,],dem=m5[2:5,],rep=m6[2:5,],.id="pid")
  tcost$subject<-as.factor(c(1,1,1,1,2,2,2,2,3,3,3,3))
  taca<-bind_rows(all=m1[2:5,],dem=m2[2:5,],rep=m3[2:5,],.id="pid")
  taca$subject<-as.factor(c(1,1,1,1,2,2,2,2,3,3,3,3))
  tcost$conf.low2<-tcost$estimate-1.645*tcost$std.error
  tcost$conf.high2<-tcost$estimate+1.645*tcost$std.error
  taca$conf.low2<-taca$estimate-1.645*taca$std.error
  taca$conf.high2<-taca$estimate+1.645*taca$std.error
  
  ##partisan heterogeneity models
  het1<-tidy(lm_robust(aca~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca)))
  het2<-tidy(lm_robust(cost~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca)))
  
  ##storing heterogeneity estimates in dfs
  hcost<-het2[12:15,]
  haca<-het1[12:15,]
  hcost$conf.low2<-hcost$estimate-1.645*hcost$std.error
  hcost$conf.high2<-hcost$estimate+1.645*hcost$std.error
  haca$conf.low2<-haca$estimate-1.645*haca$std.error
  haca$conf.high2<-haca$estimate+1.645*haca$std.error
  
  
  
  
  ##Common theme f
  th<-theme(panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            axis.title.x=element_blank(),
            legend.position = c(0.3, 0.85),
            legend.text=element_text(size=7),
            legend.key.size = unit(2, 'mm'),
            plot.title = element_text(size=8,hjust=0.5),
            axis.title.y= element_text(size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=7))
  
  
  
  ggplot(data=taca%>%subset(pid!="all"), aes(x=term, y=estimate, shape=pid,color=pid))+ 
    geom_point(aes(),position=position_dodge(0.3),size=3,alpha=1)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c("black","navy","red4"))+
    theme_bw()+
    scale_x_discrete(breaks=c("cond1","cond2","cond3","cond4"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.3), size=0.5)+
    #geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.3), size=1.5, alpha=0.6)+
    labs(title="(A) Treatment Effect on Attitude toward ACA",x="", y = "Difference from Placebo Condition")+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    ylim(-0.2,0.2)+
    th
  ggsave("fig1a.png",width=3.25,height=2.5, dpi = 2400)
  
  
  ggplot(data=tcost%>%subset(pid!="all"), aes(x=term, y=estimate,shape=pid,color=pid))+ 
    geom_point(aes(),position=position_dodge(0.3),size=3,alpha=1)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c("black","navy","red4"))+
    theme_bw()+
    scale_x_discrete(breaks=c("cond1","cond2","cond3","cond4"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.3), size=0.5)+
   # geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.3), size=0.6, alpha=0.6)+
    labs(title="(B) Treatment Effect on Belief (ACA Saves Cost)",x="", y = "Difference from Placebo Condition")+
    ylim(-0.2,0.2)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    th
  ggsave("fig1b.png",width=3.25,height=2.5, dpi = 2400)
  
  ggplot(data=haca, aes(x=term, y=estimate))+ 
    geom_point(aes(),size=3,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_discrete(breaks=c("cond1:dem","cond2:dem","cond3:dem","cond4:dem"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.5)+
    #  geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(C) Partisan Difference in Effect on Attitude",x="", y = "Diff-in-Diff (Dem - Rep)")+
    ylim(-0.2,0.2)+
    annotate(geom="text",x ="cond1:dem", y=c(-0.18,0.18),
             label=c("Negative Diff = Narrowing Partisan Gap",
                     "Positive Diff = Widening Partisan Gap"),
             size=1.8,hjust=0)+  th
  ggsave("fig1c.png",width=3.25,height=2.5, dpi = 2400)
  
  ggplot(data=hcost, aes(x=term, y=estimate))+ 
    geom_point(aes(),size=3,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_discrete(breaks=c("cond1:dem","cond2:dem","cond3:dem","cond4:dem"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.5)+
   # geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(D) Partisan Difference in Effect on Belief",x="", y = "Diff-in-Diff (Dem - Rep)")+
    ylim(-0.2,0.2)+
    annotate(geom="text",x ="cond1:dem", y=c(-0.18,0.18),
             label=c("Negative Diff = Narrowing Partisan Gap",
                     "Positive Diff = Widening Partisan Gap"),
             size=1.8,hjust=0)+  th
  ggsave("fig1d.png",width=3.25,height=2.5, dpi = 2400)
  
  
  
  aca%>%
    mutate(cond = fct_relevel(cond, "2"))%>%
    filter(dem==1)%>%
    lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=.) # strong con - weak con for dem = -0.06 (p < 0.0005) 
  
  aca%>%
    mutate(cond = fct_relevel(cond, "2"))%>%
    filter(dem==0)%>%
    lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=.) # strong con - weak con for rep = -0.03 (p < 0.1) 
  
  aca%>%
    mutate(cond = fct_relevel(cond, "3"))%>%
    filter(dem==1)%>%
    lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=.) # strong con - weak con for dem = 0.03 (p < 0.05) 
  
  aca%>%
    mutate(cond = fct_relevel(cond, "3"))%>%
    filter(dem==0)%>%
    lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=.) # strong con - weak con for rep = 0.02 (ns) 
  
  
  aca%>%
    mutate(cond = fct_relevel(cond, "2"))%>%
    filter(dem==1)%>%
    lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=.) # strong con - weak con for dem = -0.03 (p < 0.05) 
  
  aca%>%
    mutate(cond = fct_relevel(cond, "2"))%>%
    filter(dem==0)%>%
    lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=.) # strong con - weak con for rep = -0.06 (p < 0.05) 
  
  aca%>%
    mutate(cond = fct_relevel(cond, "3"))%>%
    filter(dem==1)%>%
    lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=.) # strong con - weak con for dem = 0.04 (p < 0.05) 
  
  aca%>%
    mutate(cond = fct_relevel(cond, "3"))%>%
    filter(dem==0)%>%
    lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=.) # strong con - weak con for rep = 0.06 (p < 0.05) 
  
  
  
  
  
  # Figure 2 (treatment effect decay) ############
  
  a<-lm_robust(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca, wave3==1))
  a3<-lm_robust(w3aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca, wave3==1))
  a4<-lm_robust(w4aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  b<-lm_robust(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca, wave3==1))
  b3<-lm_robust(w3cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca, wave3==1))
  b4<-lm_robust(w4cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  
  ft <- function(x) {linearHypothesis(x, c("cond1=0",
                                           "cond2=0",
                                           "cond3=0",
                                           "cond4=0",
                                           "cond1:dem=0",
                                           "cond2:dem=0",
                                           "cond3:dem=0",
                                           "cond4:dem=0"
  ), test = "F", white.adjust = "hc2" )}
  
  ft(a3)
  ft(a4)
  ft(b3)
  ft(b4)
  
  long<-bind_rows(
    a%>%glht(linfct=c("(-2*cond1-2*cond2+2*cond3+2*cond4+cond3:dem+cond4:dem-cond1:dem-cond2:dem)/8=0"))%>%tidy(),
    a%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    a%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    b%>%glht(linfct=c("(-2*cond1-2*cond2+2*cond3+2*cond4+cond3:dem+cond4:dem-cond1:dem-cond2:dem)/8=0"))%>%tidy(),
    b%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    b%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    a3%>%glht(linfct=c("(-2*cond1-2*cond2+2*cond3+2*cond4+cond3:dem+cond4:dem-cond1:dem-cond2:dem)/8=0"))%>%tidy(),
    a3%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    a3%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    b3%>%glht(linfct=c("(-2*cond1-2*cond2+2*cond3+2*cond4+cond3:dem+cond4:dem-cond1:dem-cond2:dem)/8=0"))%>%tidy(),
    b3%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    b3%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    a4%>%glht(linfct=c("(-2*cond1-2*cond2+2*cond3+2*cond4+cond3:dem+cond4:dem-cond1:dem-cond2:dem)/8=0"))%>%tidy(),
    a4%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    a4%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    b4%>%glht(linfct=c("(-2*cond1-2*cond2+2*cond3+2*cond4+cond3:dem+cond4:dem-cond1:dem-cond2:dem)/8=0"))%>%tidy(),
    b4%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    b4%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy()
  )
  
  long$info<-rep(c("p","c","u"),6)%>%factor(levels = c("p","u","c"))
  long$dv<-rep(c("a","a","a","b","b","b"),3)
  long$wave<-c(rep(2,6),rep(3,6),rep(4,6))
  
  long$conf.low<-long$estimate-1.96*long$std.error
  long$conf.high<-long$estimate+1.96*long$std.error
  long$conf.low2<-long$estimate-1.645*long$std.error
  long$conf.high2<-long$estimate+1.645*long$std.error
  
  recall<-bind_rows(
    (lm_robust(w2recall~congenial,aca)%>%tidy())[1,],
    (lm_robust(w2recall~uncongenial,aca)%>%tidy())[1,],
    (lm_robust(w3recall~congenial,aca)%>%tidy())[1,],
    (lm_robust(w3recall~uncongenial,aca)%>%tidy())[1,],
    (lm_robust(w4recall~congenial,aca)%>%tidy())[1,],
    (lm_robust(w4recall~uncongenial,aca)%>%tidy())[1,])
  
  recall$info<-rep(c("u","c"),3)
  recall$wave<-c(2,2,3,3,4,4)
  
  
  
  
  
  ggplot(data=long%>%subset(dv=="a" & info!="p"), aes(x=wave, y=estimate, color=info, fill = info,shape = info,linetype = info))+ 
    geom_point(aes(),size=1,alpha=1)+ 
    geom_line(aes(),size=0.3)+geom_ribbon(aes(ymin=conf.low, ymax=conf.high), alpha = 0.2, colour = NA)+
    scale_shape_manual(name = c(""),
                       breaks=c("p","u","c"),
                       labels = c("Pooled","Uncongenial", "Congenial"),
                       values=c(8,3, 4))+
    scale_linetype_manual(name = c(""),
                          breaks=c("p","u","c"),
                          labels = c("Pooled","Uncongenial", "Congenial"),
                          values=c(1,2,1))+
    scale_fill_manual(name = c(""),
                      breaks=c("p","u","c"),
                      labels = c("Pooled","Uncongenial", "Congenial"),
                      values=c("black","#E7A500","black"))+ 
    scale_color_manual(name = c(""),
                       breaks=c("p","u","c"),
                       labels = c("Pooled","Uncongenial", "Congenial"),
                       values=c("black","#E7A500","black"))+
    theme_bw()+
    scale_x_continuous(breaks=c(2,3,4),
                       labels=c("Immediate", "80\nDays", "160\nDays"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    labs(title="(A) Effects on Attitude",x="", y = "Change toward Information (vs. Placebo)")+
    ylim(-0.1,0.15)+
    guides(fill=guide_legend(title=NULL),color=guide_legend(title=NULL),linetype=guide_legend(title=NULL),shape=guide_legend(title=NULL))+
    th+ theme(legend.position = c(0.7, 0.85))
  ggsave("fig2a.png",width=2.15,height=2.5, dpi = 2400)
  
  
  ggplot(data=long%>%subset(dv=="b" & info!="p"), aes(x=wave, y=estimate, color=info, fill = info,shape = info,linetype = info))+ 
    geom_point(aes(),size=1.5,alpha=1)+ 
    geom_line(aes(),size=0.3)+geom_ribbon(aes(ymin=conf.low, ymax=conf.high), alpha = 0.2, colour = NA)+
    scale_shape_manual(name = c(""),
                       breaks=c("p","u","c"),
                       labels = c("Pooled","Uncongenial", "Congenial"),
                       values=c(8,3, 4))+
    scale_linetype_manual(name = c(""),
                          breaks=c("p","u","c"),
                          labels = c("Pooled","Uncongenial", "Congenial"),
                          values=c(1,2,1))+
    scale_fill_manual(name = c(""),
                      breaks=c("p","u","c"),
                      labels = c("Pooled","Uncongenial", "Congenial"),
                      values=c("black","#E7A500","black"))+
    scale_color_manual(name = c(""),
                       breaks=c("p","u","c"),
                       labels = c("Pooled","Uncongenial", "Congenial"),
                       values=c("black","#E7A500","black"))+
    theme_bw()+
    scale_x_continuous(breaks=c(2,3,4),
                       labels=c("Immediate", "80\nDays", "160\nDays"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    labs(title="(B) Effects on Belief",x="", y = "Change toward Information (vs. Placebo)")+
    ylim(-0.1,0.15)+
    guides(fill=guide_legend(title=NULL),color=guide_legend(title=NULL),linetype=guide_legend(title=NULL),shape=guide_legend(title=NULL))+
    th+ theme(legend.position = c(0.7, 0.85))
  ggsave("fig2b.png",width=2.15,height=2.5, dpi = 2400)
  
  ggplot(data=recall, aes(x=wave, y=estimate, color=info, fill = info,shape = info,linetype = info))+ 
    geom_point(aes(),size=1.5,alpha=1)+ 
    geom_line(aes(),size=0.3)+geom_ribbon(aes(ymin=conf.low, ymax=conf.high), alpha = 0.2, colour = NA)+
    scale_shape_manual(name = c(""),
                       breaks=c("p","u","c"),
                       labels = c("Pooled","Uncongenial", "Congenial"),
                       values=c(8,3, 4))+
    scale_linetype_manual(name = c(""),
                          breaks=c("p","u","c"),
                          labels = c("Pooled","Uncongenial", "Congenial"),
                          values=c(1,2,1))+
    scale_fill_manual(name = c(""),
                      breaks=c("p","u","c"),
                      labels = c("Pooled","Uncongenial", "Congenial"),
                      values=c("black","#E7A500","black"))+
    scale_color_manual(name = c(""),
                       breaks=c("p","u","c"),
                       labels = c("Pooled","Uncongenial", "Congenial"),
                       values=c("black","#E7A500","black"))+
    theme_bw()+
    scale_x_continuous(breaks=c(2,3,4),
                       labels=c("Immediate", "80\nDays", "160\nDays"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    labs(title="(C) Information Recall",x="", y = "Pr(Correct Answer)")+
    guides(fill=guide_legend(title=NULL),color=guide_legend(title=NULL),linetype=guide_legend(title=NULL),shape=guide_legend(title=NULL))+
    th+ theme(legend.position = c(0.7, 0.85))
  ggsave("fig2c.png",width=2.15,height=2.5, dpi = 2400)
  
  
  #rm(list=setdiff(ls(), c("aca","aca18")))
  
  
  
  
  
  
  
  
  # Figure 3: Effect of Priming Treatments on Affective Polarization ----
  
  
  
  ap<-  bind_rows(
    (lm_robust(inparty~priming,aca18)%>%tidy())[2,],
    (lm_robust(inparty~priming,aca18%>%subset(dem==1))%>%tidy())[2,],
    (lm_robust(inparty~priming,aca18%>%subset(dem==0))%>%tidy())[2,],
    (lm_robust(outparty~priming,aca18)%>%tidy())[2,],
    (lm_robust(outparty~priming,aca18%>%subset(dem==1))%>%tidy())[2,],
    (lm_robust(outparty~priming,aca18%>%subset(dem==0))%>%tidy())[2,],
    (lm_robust(ap~priming,aca18)%>%tidy())[2,],
    (lm_robust(ap~priming,aca18%>%subset(dem==1))%>%tidy())[2,],
    (lm_robust(ap~priming,aca18%>%subset(dem==0))%>%tidy())[2,]
  )
  
  ap$pid<-rep(c("all","dem","rep"),3)
  ap$term<-c(1,1,1,2,2,2,3,3,3)
  ap$pid<-factor(ap$pid,levels = c("dem","rep","all"))
  
  ggplot(data=subset(ap), aes(x=term, y=estimate,shape=pid,color=pid))+ 
    geom_point(aes(),size=3,alpha=1,position=position_dodge(0.5))+ 
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep","all"),
                       labels = c("Democrats","Republicans","Pooled"),
                       values=c(16, 17,15))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep","all"),
                       labels = c("Democrats","Republicans","Pooled"),
                       values=c("navy","red4","black"))+
    theme_bw()+
    scale_x_continuous(breaks=c(1,2,3),
                       labels=c("In-Party", "Out-Party", "Affective Polarization"))+
    theme(text=element_text(size=9))+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high), size=0.5,position=position_dodge(0.5))+
    labs(title="Univalent Prime vs. Ambivalent Prime",x="", y = "Difference from the Ambivalent Condition")+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    th+theme(legend.position = c(0.2, 0.85))
  ggsave("fig3.png",width=3.25,height=2.5, dpi = 2400)
  
  
  # Figure 4 treatment effects (study 2) ----
  
  #### Analysis
  
  
  
  m4<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,priming==0)))
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0)))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0)))
  m10<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,priming==1)))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1)))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1)))
  
  ##hetero effect models
  het3<-tidy(lm_robust(aca~(cond+aca0+pid)*dem,data=subset(aca18,priming==0)))[9:12,]
  het4<-tidy(lm_robust(aca~(cond+aca0+pid)*dem,data=subset(aca18,priming==1)))[9:12,]
  
  ##3-way
  tri2<-tidy(lm_robust(aca~(cond+aca0+pid)*dem*priming,data=subset(aca18)))
  
  ###Storing estimates 
  
  attitude<-bind_rows(aam=m4[2:5,],dam=m5[2:5,],ram=m6[2:5,],
                      aun=m10[2:5,],dun=m11[2:5,],run=m12[2:5,],.id="type")
  attitude$pid<-rep(c(rep("all",4),rep("dem",4),rep("rep",4)),2)
  attitude$x<-c(rep(c(1,2,5,6),3),rep(c(3,4,7,8),3))
  attitude$conf.low2<-attitude$estimate-1.645*attitude$std.error
  attitude$conf.high2<-attitude$estimate+1.645*attitude$std.error
  
  attitude.het<-bind_rows(het3,het4)
  attitude.het$x<-c(1,2,5,6,3,4,7,8)
  attitude.het$conf.low2<-attitude.het$estimate-1.645*attitude.het$std.error
  attitude.het$conf.high2<-attitude.het$estimate+1.645*attitude.het$std.error
  
  
  
  m<-lm_robust(aca~(cond+aca0+pid)*priming*dem,aca18)
  md<-lm_robust(aca~(cond+aca0+pid)*priming*rep,aca18) #marginal effects among dems
  mr<-lm_robust(aca~(cond+aca0+pid)*priming*dem,aca18) #marginal effects among reps
  
  attitude.diff<-bind_rows(
    md%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    md%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    md%>%glht(linfct=c("cond1:priming=0"))%>%tidy(), 
    md%>%glht(linfct=c("cond2-cond1+cond2:priming=0"))%>%tidy(),
    md%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    md%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    md%>%glht(linfct=c("cond3:priming=0"))%>%tidy(), 
    md%>%glht(linfct=c("cond4-cond3+cond4:priming=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond1:priming=0"))%>%tidy(), 
    mr%>%glht(linfct=c("cond2-cond1+cond2:priming=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond3:priming=0"))%>%tidy(), 
    mr%>%glht(linfct=c("cond4-cond3+cond4:priming=0"))%>%tidy()
  )
  attitude.diff$x<-rep(1:8,2)
  attitude.diff$pid<-c(rep("dem",8),rep("rep",8))
  attitude.diff[c(1,5,9,13),2:6]<-NA
  attitude.diff$conf.low2<-attitude.diff$estimate-1.645*attitude.diff$std.error
  attitude.diff$conf.high2<-attitude.diff$estimate+1.645*attitude.diff$std.error
  attitude.diff$conf.low<-attitude.diff$estimate-1.96*attitude.diff$std.error
  attitude.diff$conf.high<-attitude.diff$estimate+1.96*attitude.diff$std.error
  
  
  
  
  attitude.tri<-bind_rows(
    m%>%glht(linfct=c("cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond1:priming:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond2:priming:dem+cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:dem-cond3:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:dem-cond3:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond3:priming:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:priming:dem+cond4:dem-cond3:dem=0"))%>%tidy()
  )
  attitude.tri[1,2:6]<-NA
  attitude.tri[5,2:6]<-NA
  attitude.tri$x<-1:8
  
  attitude.tri$conf.low<-attitude.tri$estimate-1.96*attitude.tri$std.error
  attitude.tri$conf.high<-attitude.tri$estimate+1.96*attitude.tri$std.error
  
  attitude.tri$conf.low2<-attitude.tri$estimate-1.645*attitude.tri$std.error
  attitude.tri$conf.high2<-attitude.tri$estimate+1.645*attitude.tri$std.error
  
  
  
  # average divergence in att under hostile
  
  m%>%
    glht(linfct = "((cond2:dem+cond4:dem)*2+
         cond2:priming:dem+cond4:priming:dem+
         cond1:dem+cond3:dem+
         cond1:priming:dem+cond3:priming:dem )/6=0")%>%
    tidy()
  
  # diff between average divergence in att under hostile vs divergence under non-hostile
  
  m%>%glht(linfct=c("(2*cond2:dem-2*cond1:dem+
   cond1:priming:dem+
   cond2:priming:dem+
   2*cond4:dem-2*cond3:dem+
   cond3:priming:dem+
   cond4:priming:dem)/6=0"))%>%tidy()
  
  
  th<-theme(panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            axis.title.x=element_blank(),
            legend.position = c(0.85, 0.25),
            legend.text=element_text(size=7),
            legend.key.size = unit(1.5, 'mm'),
            legend.background = element_rect(fill="transparent"),
            plot.title = element_text(size=9,hjust=0.5),
            axis.title.y= element_text(size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=7))
  
  xlab<- c("(1)\nCon\nCivil\nAmbi.","(2)\nCon\nUncivil\nAmbi.","(3)\nCon\nCivil\nUniv.","(4)\nCon\nUncivil\nUniv.",
           "(5)\nPro\nCivil\nAmbi.","(6)\nPro\nUncivil\nAmbi.","(7)\nPro\nCivil\nUniv.","(8)\nPro\nUncivil\nUniv.")
  
  
  
  ### Creating Figures 3
  ggplot(data=subset(attitude,pid!="all"), aes(x=x, y=estimate,shape=pid,color=pid))+ 
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_point(aes(),position=position_dodge(0.5),size=3)+ 
    annotate(geom="text",x =c(1,3,5,7), y=c(0.18),
             label=c("Baseline", "Hostile Contexts","Baseline", "Hostile Contexts"),
             size=2,hjust=0.5)+
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c(16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c("navy","red4"))+
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    # geom_vline(xintercept = c(1.5,4.5,5.5), linetype="dotted",size=0.3,color="grey")+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.5)+
   # geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=1.5, alpha=0.6)+
    labs(title="(A) Treatment Effect on Attitude toward ACA",x="", y = "Difference from Placebo")+
    ylim(-0.2,0.2)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    th
 # ggsave("fig4a.pdf",width=3.25,height=2.5)
  ggsave("fig4a.png",width=3.25,height=2.5, dpi = 2400)
  
  
  
  
  ggplot(data=subset(attitude.diff), aes(x=x, y=estimate,shape=pid,color=pid))+ 
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_point(aes(),position=position_dodge(0.5),size=3)+ 
    annotate(geom="text",x =c(3,7,3,7,1,5), y=c(0.18,0.18,-0.18,-0.18,-0.02,-0.02),
             label=c("Positive =\nWeaker effect of con","Positive =\nStronger effect of pro",
                     "Negative =\nStronger effect of con","Negative =\nWeaker effect of pro",
                     "",""),
             size=2,hjust=0.5)+
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c(16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c("navy","red4"))+
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.5)+
 #   geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.4)+
    labs(title="(B)  Difference in Treatment Effects (vs. Baseline)",x="", y = "Diff-in-Diff (Contentious - Baseline)")+
    ylim(-0.2,0.2)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+th+
    theme(legend.position = "none")
 # ggsave("fig4b.pdf",width=3.25,height=2.5)
  ggsave("fig4b.png",width=3.25,height=2.5, dpi = 2400)
  
  
  
  
  
  ggplot(data=attitude.het, aes(x=x, y=estimate))+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_point(aes(),size=3,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.5)+
   # geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(C) Partisan Difference in Treatment Effects",x="", y = "Diff-in-Diff  (Dem - Rep)")+
    ylim(-0.2,0.2)+
    annotate(geom="text",x =4.5, y=c(-0.195,0.195),
             label=c("Negative = Treatment decreases partsan gap",
                     "Positive = Treatment increases partsan gap"),
             size=2,hjust=.5)+th
#  ggsave("fig4c.pdf",width=3.25,height=2.5)
  ggsave("fig4c.png",width=3.25,height=2.5, dpi = 2400)
  
  
  
  
  ggplot(data=attitude.tri, aes(x=x, y=estimate))+ 
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_point(aes(),size=3,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.5)+
   # geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(D) Difference in Partisan Differences (vs. Baseline)",x="", y = "Diff-in-Diff-in-Diff (Contentious - Baseline)")+
    ylim(-0.2,0.2)+
    annotate(geom="text",x =c(4.5,4.5,1,5), y=c(-0.195,0.195, -0.02, -0.02),
             label=c("Negative = Treatment decreases partsan gap more",
                     "Positive = Treatment increases partsan gap more",
                     "",""),
             size=2,hjust=.5)+
    th
#  ggsave("fig4d.pdf",width=3.25,height=2.5)
  ggsave("fig4d.png",width=3.25,height=2.5, dpi = 2400)
  
  
  
  
  
  # Figure 5 pooled effects by context #####
  
  
  md<-lm_robust(aca~(cond+aca0+pid)*priming*rep,aca18) 
  uncon1<-md%>%glht(linfct="(cond3+cond3:rep-cond1)/2=0")%>%tidy() 
  uncon2<-md%>%glht(linfct="(cond4+cond4:rep-cond2)/2=0")%>%tidy() 
  uncon3<-md%>%glht(linfct="(cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming)/2=0")%>%tidy() 
  uncon4<-md%>%glht(linfct="(cond4+cond4:rep+cond4:priming+cond4:priming:rep-cond2-cond2:priming)/2=0")%>%tidy() 
  uncon5<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  uncon6<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3:priming+cond3:priming:rep-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming-2*cond3-2*cond3:rep+2*cond1)/6=0")%>%tidy() 
  attitude.uncongenial<-bind_rows(uncon1,uncon2,uncon3,uncon4,uncon5,uncon6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  xtable::xtable(attitude.uncongenial)
  # combined together, affective environments undercut the effect of counter information by 4 percentgage points (row 6)
  
  
  #### Congenial info effects across different contexts
  mr<-lm_robust(aca~(cond+aca0+pid)*priming*dem,aca18) 
  conge1<-mr%>%glht(linfct="(cond3+cond3:dem-cond1)/2=0")%>%tidy() 
  conge2<-mr%>%glht(linfct="(cond4+cond4:dem-cond2)/2=0")%>%tidy() 
  conge3<-mr%>%glht(linfct="(cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming)/2=0")%>%tidy() 
  conge4<-mr%>%glht(linfct="(cond4+cond4:dem+cond4:priming+cond4:priming:dem-cond2-cond2:priming)/2=0")%>%tidy() 
  conge5<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  conge6<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3:priming+cond3:priming:dem-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming-2*cond3-2*cond3:dem+2*cond1)/6=0")%>%tidy() 
  # difference in cognenial info effect in affective environ vs. non-affective environ
  attitude.congenial<-bind_rows(conge1,conge2,conge3,conge4,conge5,conge6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  
  
  
  attitude.conuncon<-bind_rows(attitude.congenial, attitude.uncongenial)[c(1,5,6,7,11,12),]%>%
    bind_cols(info=c(rep("congenial",3),rep("uncongenial",3)), x = c(1,2,3,1,2,3))
  
  
  attitude.conuncon$conf.low<-attitude.conuncon$estimate-1.96*attitude.conuncon$std.error
  attitude.conuncon$conf.high<-attitude.conuncon$estimate+1.96*attitude.conuncon$std.error
  
  attitude.conuncon$conf.low2<-attitude.conuncon$estimate-1.645*attitude.conuncon$std.error
  attitude.conuncon$conf.high2<-attitude.conuncon$estimate+1.645*attitude.conuncon$std.error
  
  
  
  
  
  ggplot(data=attitude.conuncon[c(-3,-6),], aes(x=x, y=estimate, color=info))+ 
    geom_point(aes(),size=3,stroke =.4,position=position_dodge(0.1))+ 
    geom_line(position=position_dodge(0.1), size = 0.4, alpha = 0.7, linetype = "dashed")+
    theme_bw()+
    scale_color_manual(name = c(""),
                       breaks=c("congenial","uncongenial"),
                       labels = c("Congenial", "Uncongenial"),
                       values=c("black","#E7A500"))+
    scale_x_continuous(breaks = 1:2, limits = c(.5,2.5),
                       labels=c("Baseline\n(Civil and Ambivalent)","Contentious\n(Uncivil, Univalent, or both)"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.1), size=0.5)+
   # geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.1), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(A) Effects of (Un)congenial Information (Pooled)",x="", y = "Pooled Effects on Belief (toward Information)")+
    annotate(geom="text",x =1.5, y=c(0.068,0.036),
             label=c("+0.03","-0.04"),
             color=c("black","#E7A500"),size=2.4,hjust=.5)+
    th+  theme(legend.position = c(0.18, 0.2))
  ggsave("fig5a.png",width=3.25,height=2.5, dpi = 2400)
  
  
  ggplot(data=attitude.conuncon[c(3,6),], aes(x=x, y=estimate, color=info))+ 
    geom_point(aes(),size=3,stroke =.4)+ 
    theme_bw()+
    scale_color_manual(name = c(""),
                       breaks=c("congenial","uncongenial"),
                       labels = c("Congenial", "Uncongenial"),
                       values=c("black","#E7A500"))+
    scale_x_continuous(breaks = 3, limits = c(2.5,3.5),
                       labels=c("Contentious vs. Baseline\n"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high), size=0.5)+
    #geom_linerange(aes(ymin = conf.low2, ymax = conf.high2), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(B) Difference in Effects (vs. Baseline)",x="", y = "Difference in Effects (Contentious - Baseline)")+
    th+  theme(legend.position = c(0.25, 0.2))
  ggsave("fig5b.png",width=3.25,height=2.5, dpi = 2400)
  
  
  
  
  
  ## APPENDIX A ############
  
  
  # Table S1: Treatment Effects on ACA Attitude and Belief #####
  
  
  m1<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  m2<-lm(aca~(cond)*dem,data=subset(aca))
  m3<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1))
  m4<-lm(aca~(cond)*dem,data=subset(aca,wgt2==1))
  m5<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  m6<-lm(cost~(cond)*dem,data=subset(aca))
  m7<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1))
  m8<-lm(cost~(cond)*dem,data=subset(aca,wgt2==1))
  
  
  stargazer(m1,m2,m3,m4,m5,m6,m7,m8, 
            se=starprep(m1,m2,m3,m4,m5,m6,m7,m8,se_type="HC2"),
            order = c(1,2,3,4,10,11,12,13,14,5,6,7,8,9,15,16,17,18,19),
            dep.var.labels = c("DV = Attitude toward the ACA","DV = Belief that ACA Saves Healthcare Costs"),
            covariate.labels = c("Strong Con", "Weak Con", "Weak Pro", "Strong Pro",
                                 "Democrat","Strong Con $\\times$ Dem","Weak Con $\\times$ Dem","Weak Pro $\\times$ Dem", "Strong Pro $\\times$ Dem",
                                 "W1 Attitude", "W1 Belief", "W1 PID Cont.", "W1 Obama", "W1 Obama HC",
                                 "W1 Attitude $\\times$ Dem", "W1 Belief $\\times$ Dem", "W1 PID $\\times$ Dem", "W1 Obama $\\times$ Dem", "W1 Obama HC $\\times$ Dem"),
            star.cutoffs = c(.05, .01, .001),
            add.lines = list(c("Reported in Main Text","\\checkmark","","","","\\checkmark","","",""),
                             c("Covariates","\\checkmark","","\\checkmark","","\\checkmark","","\\checkmark",""),
                             c("Shirkers Dropped","","","\\checkmark","\\checkmark","","","\\checkmark","\\checkmark")),
            #         no.space = TRUE,
            style = "ajps",
            digits= 2,keep.stat = c("n","adj.rsq"))
  #rm(list=setdiff(ls(), c("aca","aca18")))
  
  
  # Table S2:  Estimates of Figure 1 in Tabular Form #####
  
  md<-lm_robust(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))%>%tidy()
  mr<-lm_robust(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*rep,data=subset(aca))%>%tidy()
  int1<-lm_robust(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))%>%
    glht(linfct=c("(cond1:dem+cond2:dem+cond3:dem+cond4:dem)/4=0"))%>%tidy()
  md2<-lm_robust(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))%>%tidy()
  mr2<-lm_robust(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*rep,data=subset(aca))%>%tidy()
  int2<-lm_robust(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))%>%
    glht(linfct=c("(cond1:dem+cond2:dem+cond3:dem+cond4:dem)/4=0"))%>%tidy()
  
  
  col.names<-c("Outcome","Parameter","Definition","Referenc","Coef","SE")
  col1<-c("$\\beta_1$","$\\beta_2$","$\\beta_3$","$\\beta_4$",
          "$\\beta_1+\\delta_1$","$\\beta_2+\\delta_2$","$\\beta_3+\\delta_3$","$\\beta_4+\\delta_4$",
          "$\\delta_1$","$\\delta_2$","$\\delta_3$","$\\delta_4$",
          "$(\\delta_1+\\delta_2+\\delta_3+\\delta_4)/4$")%>%rep(2)
  col2<-c("Strong con effect on Rep","Weak con effect on Rep", "Weak pro effect on Rep", "Strong pro effect on Rep",
          "Strong con effect on Dem","Weak con effect on Dem", "Weak pro effect on Dem", "Strong pro effect on Dem",
          "Partisan difference in strong con effect","Partisan difference in weak con effect", 
          "Partisan difference in weak pro Effect", "Partisan difference in strong pro effect",
          "Average of partisan differences across conditions")%>%rep(2)
  bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')}
  
  
  tab.s1<-bind_cols(x=rep(NA,26),y=rep(NA,26),z=rep(NA,26),k=rep(NA,26),
                    bind_rows(md[2:5,2:3],mr[2:5,2:3],md[12:15,2:3],int1[,c(3,4)],
                              md2[2:5,2:3],mr2[2:5,2:3],md2[12:15,2:3],int2[,c(3,4)]))%>%tibble()
  names(tab.s1)<-col.names
  tab.s1[1]<-c(rep("Attitude",13),rep("Belief",13))
  tab.s1[2]<-col1
  tab.s1[3]<-col2
  tab.s1[4]<-c("Fig \\ref{s1}A"%>%rep(4),"Fig \\ref{s1}A"%>%rep(4),"Fig \\ref{s1}C"%>%rep(4),"Text",
               "Fig \\ref{s1}B"%>%rep(4),"Fig \\ref{s1}B"%>%rep(4),"Fig \\ref{s1}D"%>%rep(4),"Text")
  print(xtable(tab.s1),sanitize.text.function=function(x){x}, include.rownames=F,sanitize.colnames.function=bold)
  
  
  
  
  # Figure S1: Decay of Treatment Effects (Study 1) ####
  
  
  taca.lr<-bind_rows(
    tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca, wave3==1)))[2:5,],
    tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1&dem==1)))[2:5,],
    tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1&dem==0)))[2:5,],
    tidy(lm_robust(w3aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1)))[2:5,],
    tidy(lm_robust(w3aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1&dem==1)))[2:5,],
    tidy(lm_robust(w3aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1&dem==0)))[2:5,],
    tidy(lm_robust(w4aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca)))[2:5,],
    tidy(lm_robust(w4aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))[2:5,],
    tidy(lm_robust(w4aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))[2:5,]
  )
  
  
  
  
  taca.lr$pid<-rep(c(rep("all",4),rep("dem",4),rep("rep",4)),3)
  taca.lr$conf.low2<-taca.lr$estimate-1.645*taca.lr$std.error
  taca.lr$conf.high2<-taca.lr$estimate+1.645*taca.lr$std.error
  taca.lr$outcome<-c(rep("Immediate",12),rep("In 80 Days",12),rep("In 160 Days",12))%>%
    factor(levels = c("Immediate","In 80 Days","In 160 Days"))
  
  
  ggplot(data=taca.lr, aes(x=term, y=estimate, shape=pid,color=pid))+ 
    geom_point(aes(),position=position_dodge(0.5),size=1.8,alpha=1)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c("black","navy","red4"))+
    theme_bw()+
    scale_x_discrete(breaks=c("cond1","cond2","cond3","cond4"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    labs(title="Long-Run Treatment Effects on Attitude toward ACA",x="", y = "Difference from Placebo Condition")+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    ylim(-0.2,0.2)+
    facet_grid(. ~ outcome)+
    theme(panel.grid.major=element_blank(),
          panel.grid.minor=element_blank(),
          panel.border=element_rect(colour="black"),
          strip.background = element_rect(fill ="white",color = "white",size=1),
          axis.title.x=element_blank(),
          legend.position = c(0.1, 0.85),
          legend.text=element_text(size=7),
          legend.key.size = unit(2, 'mm'),
          plot.title = element_text(size=8,hjust=0.5),
          axis.title.y= element_text(size=7),
          axis.text.x = element_text(color = "black", size=7),
          axis.text.y = element_text(color = "black", size=7))
  ggsave("figs1a.png",width=6.5,height=2.5, dpi = 900)
  
  
  
  
  tcost.lr<-bind_rows(
    tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca, wave3==1)))[2:5,],
    tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1&dem==1)))[2:5,],
    tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1&dem==0)))[2:5,],
    tidy(lm_robust(w3cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1)))[2:5,],
    tidy(lm_robust(w3cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1&dem==1)))[2:5,],
    tidy(lm_robust(w3cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,wave3==1&dem==0)))[2:5,],
    tidy(lm_robust(w4cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca)))[2:5,],
    tidy(lm_robust(w4cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))[2:5,],
    tidy(lm_robust(w4cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))[2:5,]
  )
  
  tcost.lr$pid<-rep(c(rep("all",4), rep("dem",4),rep("rep",4)),3)
  tcost.lr$conf.low2<-tcost.lr$estimate-1.645*tcost.lr$std.error
  tcost.lr$conf.high2<-tcost.lr$estimate+1.645*tcost.lr$std.error
  tcost.lr$outcome<-c(rep("Immediate",12),rep("In 80 Days",12),rep("In 160 Days",12))%>%
    factor(levels = c("Immediate","In 80 Days","In 160 Days"))
  
  
  
  
  
  ggplot(data=tcost.lr, aes(x=term, y=estimate, shape=pid,color=pid))+ 
    geom_point(aes(),position=position_dodge(0.5),size=1.8,alpha=1)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c("black","navy","red4"))+
    theme_bw()+
    scale_x_discrete(breaks=c("cond1","cond2","cond3","cond4"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    labs(title="Long-Run Treatment Effects on Belief that ACA Saves Costs",x="", y = "Difference from Placebo Condition")+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    ylim(-0.2,0.2)+
    facet_grid(. ~ outcome)+
    theme(panel.grid.major=element_blank(),
          panel.grid.minor=element_blank(),
          panel.border=element_rect(colour="black"),
          strip.background = element_rect(fill ="white",color = "white",size=1),
          axis.title.x=element_blank(),
          legend.position = c(0.1, 0.85),
          legend.text=element_text(size=7),
          legend.key.size = unit(2, 'mm'),
          plot.title = element_text(size=8,hjust=0.5),
          axis.title.y= element_text(size=7),
          axis.text.x = element_text(color = "black", size=7),
          axis.text.y = element_text(color = "black", size=7))
  ggsave("figs1b.png",width=6.5,height=2.5, dpi = 900)
  
  
  # Table S3: Full Regression Estimates Treatment Effects Measured at Waves 3 (80 Days) and 4 (160 Days) ----
  
  #### Wave 2
  
  m1<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wave3==1))
  m2<-lm(aca~(cond)*dem,data=subset(aca,wave3==1))
  m3<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1&wave3==1))
  m4<-lm(aca~(cond)*dem,data=subset(aca,wgt2==1&wave3==1))
  m5<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wave3==1))
  m6<-lm(cost~(cond)*dem,data=subset(aca,wave3==1))
  m7<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1&wave3==1))
  m8<-lm(cost~(cond)*dem,data=subset(aca,wgt2==1&wave3==1))
  
  
  stargazer(m1,m2,m3,m4,m5,m6,m7,m8, 
            se=starprep(m1,m2,m3,m4,m5,m6,m7,m8,se_type="HC2"),
            order = c(1,2,3,4,10,11,12,13,14,5,6,7,8,9,15,16,17,18,19),
            dep.var.labels = c("DV = W3 Attitude toward the ACA","DV = W3 Belief that ACA Saves Healthcare Costs"),
            covariate.labels = c("Strong Con", "Weak Con", "Weak Pro", "Strong Pro",
                                 "Democrat","Strong Con $\\times$ Dem","Weak Con $\\times$ Dem","Weak Pro $\\times$ Dem", "Strong Pro $\\times$ Dem",
                                 "W1 Attitude", "W1 Belief", "W1 PID Cont.", "W1 Obama", "W1 Obama HC",
                                 "W1 Attitude $\\times$ Dem", "W1 Belief $\\times$ Dem", "W1 PID $\\times$ Dem", "W1 Obama $\\times$ Dem", "W1 Obama HC $\\times$ Dem"),
            star.cutoffs = c(.05, .01, .001),
            add.lines = list(c("Reported in Main Text","\\checkmark","","","","\\checkmark","","",""),
                             c("Covariates","\\checkmark","","\\checkmark","","\\checkmark","","\\checkmark",""),
                             c("Shirkers Dropped","","","\\checkmark","\\checkmark","","","\\checkmark","\\checkmark")),
            #         no.space = TRUE,
            style = "ajps",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  
  #### Wave 3 
  
  m1<-lm(w3aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wave3==1))
  m2<-lm(w3aca~(cond)*dem,data=subset(aca,wave3==1))
  m3<-lm(w3aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1&wave3==1))
  m4<-lm(w3aca~(cond)*dem,data=subset(aca,wgt2==1&wave3==1))
  m5<-lm(w3cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wave3==1))
  m6<-lm(w3cost~(cond)*dem,data=subset(aca,wave3==1))
  m7<-lm(w3cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1&wave3==1))
  m8<-lm(w3cost~(cond)*dem,data=subset(aca,wgt2==1&wave3==1))
  
  
  stargazer(m1,m2,m3,m4,m5,m6,m7,m8, 
            se=starprep(m1,m2,m3,m4,m5,m6,m7,m8,se_type="HC2"),
            order = c(1,2,3,4,10,11,12,13,14,5,6,7,8,9,15,16,17,18,19),
            dep.var.labels = c("DV = W3 Attitude toward the ACA","DV = W3 Belief that ACA Saves Healthcare Costs"),
            covariate.labels = c("Strong Con", "Weak Con", "Weak Pro", "Strong Pro",
                                 "Democrat","Strong Con $\\times$ Dem","Weak Con $\\times$ Dem","Weak Pro $\\times$ Dem", "Strong Pro $\\times$ Dem",
                                 "W1 Attitude", "W1 Belief", "W1 PID Cont.", "W1 Obama", "W1 Obama HC",
                                 "W1 Attitude $\\times$ Dem", "W1 Belief $\\times$ Dem", "W1 PID $\\times$ Dem", "W1 Obama $\\times$ Dem", "W1 Obama HC $\\times$ Dem"),
            star.cutoffs = c(.05, .01, .001),
            add.lines = list(c("Reported in Main Text","\\checkmark","","","","\\checkmark","","",""),
                             c("Covariates","\\checkmark","","\\checkmark","","\\checkmark","","\\checkmark",""),
                             c("Shirkers Dropped","","","\\checkmark","\\checkmark","","","\\checkmark","\\checkmark")),
            #         no.space = TRUE,
            style = "ajps",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  #### Wave 4
  
  m1<-lm(w4aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  m2<-lm(w4aca~(cond)*dem,data=subset(aca))
  m3<-lm(w4aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1))
  m4<-lm(w4aca~(cond)*dem,data=subset(aca,wgt2==1))
  m5<-lm(w4cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  m6<-lm(w4cost~(cond)*dem,data=subset(aca))
  m7<-lm(w4cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1))
  m8<-lm(w4cost~(cond)*dem,data=subset(aca,wgt2==1))
  
  
  
  stargazer(m1,m2,m3,m4,m5,m6,m7,m8, 
            se=starprep(m1,m2,m3,m4,m5,m6,m7,m8,se_type="HC2"),
            order = c(1,2,3,4,10,11,12,13,14,5,6,7,8,9,15,16,17,18,19),
            dep.var.labels = c("DV = W4 Attitude toward the ACA","DV = W4 Belief that ACA Saves Healthcare Costs"),
            covariate.labels = c("Strong Con", "Weak Con", "Weak Pro", "Strong Pro",
                                 "Democrat","Strong Con $\\times$ Dem","Weak Con $\\times$ Dem","Weak Pro $\\times$ Dem", "Strong Pro $\\times$ Dem",
                                 "W1 Attitude", "W1 Belief", "W1 PID Cont.", "W1 Obama", "W1 Obama HC",
                                 "W1 Attitude $\\times$ Dem", "W1 Belief $\\times$ Dem", "W1 PID $\\times$ Dem", "W1 Obama $\\times$ Dem", "W1 Obama HC $\\times$ Dem"),
            star.cutoffs = c(.05, .01, .001),
            add.lines = list(c("Reported in Main Text","\\checkmark","","","","\\checkmark","","",""),
                             c("Covariates","\\checkmark","","\\checkmark","","\\checkmark","","\\checkmark",""),
                             c("Shirkers Dropped","","","\\checkmark","\\checkmark","","","\\checkmark","\\checkmark")),
            #         no.space = TRUE,
            style = "ajps",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  # Table S4: Estimates of Figures 2A and 2B in Tabular Form #####
  
  
  a<-lm_robust(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wave3==1))
  a3<-lm_robust(w3aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wave3==1))
  a4<-lm_robust(w4aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  b<-lm_robust(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wave3==1))
  b3<-lm_robust(w3cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wave3==1))
  b4<-lm_robust(w4cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  
  long<-bind_rows(
    a%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    a%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    a3%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    a3%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    a3%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    a4%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    b%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    b%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    b3%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    b3%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy(),
    b4%>%glht(linfct=c("(-cond1-cond2+cond3+cond4+cond3:dem+cond4:dem)/4=0"))%>%tidy(),
    b4%>%glht(linfct=c("(cond3+cond4-cond1-cond2-cond1:dem-cond2:dem)/4=0"))%>%tidy()
  )
  
  
  
  col.names<-c("Outcome","Parameter","Definition","Referenc","Coef","SE")
  col1<-c("$(-\\beta_1-\\beta_2+\\beta_3+\\delta_3+\\beta_4+\\delta_4)/4$",
          "$(-\\beta_1-\\delta_1-\\beta_2-\\delta_2+\\beta_3+\\beta_4)/4$")%>%rep(6)
  col2<-c("Average effect of congenial information (pooled)",
          "Average effect of uncongenial information (pooled)")%>%rep(6)
  bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')}
  
  
  tab.s1<-bind_cols(x=rep(NA,12),y=rep(NA,12),z=rep(NA,12),k=rep(NA,12),
                    long[,3:4])%>%tibble()
  names(tab.s1)<-col.names
  tab.s1[1]<-c(rep("W2 Attitude",2),rep("W3 Attitude",2),rep("W4 Attitude",2),rep("W2 Belief",2),rep("W3 Belief",2),rep("W4 Belief",2))
  tab.s1[2]<-col1
  tab.s1[3]<-col2
  tab.s1[4]<-c("Fig \\ref{s1-lr}A"%>%rep(2),"Fig \\ref{s1-lr}A"%>%rep(2),"Fig \\ref{s1-lr}A"%>%rep(2),
               "Fig \\ref{s1-lr}B"%>%rep(2),"Fig \\ref{s1-lr}B"%>%rep(2),"Fig \\ref{s1-lr}B"%>%rep(2))
  print(xtable(tab.s1),sanitize.text.function=function(x){x}, include.rownames=F,sanitize.colnames.function=bold)
  
  
  
  # Table S5: Effect of Information Congeniality on Short-Term vs. Long-Term Recall (Figure 2C) #####
  
  
  m1<-lm(w2recall~congenial,aca)
  m2<-lm(w3recall~congenial,aca)
  m3<-lm(w4recall~congenial,aca)
  m4<-lm(w3recall2~congenial,aca)
  m5<-lm(w4recall2~congenial,aca)
  
  
  stargazer(m1,m2,m3,m4,m5, 
            se=starprep(m1,m2,m3,m4,m5,se_type="HC2"),
            dep.var.labels = c("W2 Specific Facts","W3 Specific Facts", "W4 Specific Facts","W3 Position","W4 Position"),
            covariate.labels = c("Congenial"),
            star.cutoffs = c(.05, .01, .001),
            style = "ajps",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  # Figure S2: Downstream Effects on Approval of Obama (Study 1) #####
  
  
  m1<-tidy(lm_robust(obamahc~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca)))
  m2<-tidy(lm_robust(obamahc~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))
  m3<-tidy(lm_robust(obamahc~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))
  m4<-tidy(lm_robust(obama~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca)))
  m5<-tidy(lm_robust(obama~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))
  m6<-tidy(lm_robust(obama~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))
  het1<-tidy(lm_robust(obamahc~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca)))
  het2<-tidy(lm_robust(obama~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca)))
  
  ##combining regression estimates into dataframes
  tobama<-bind_rows(all=m4[2:5,],dem=m5[2:5,],rep=m6[2:5,],.id="pid")
  tobama$subject<-as.factor(c(1,1,1,1,2,2,2,2,3,3,3,3))
  tobamahc<-bind_rows(all=m1[2:5,],dem=m2[2:5,],rep=m3[2:5,],.id="pid")
  tobamahc$subject<-as.factor(c(1,1,1,1,2,2,2,2,3,3,3,3))
  tobama$conf.low2<-tobama$estimate-1.645*tobama$std.error
  tobama$conf.high2<-tobama$estimate+1.645*tobama$std.error
  tobamahc$conf.low2<-tobamahc$estimate-1.645*tobamahc$std.error
  tobamahc$conf.high2<-tobamahc$estimate+1.645*tobamahc$std.error
  ##storing heterogeneity estimates in dfs
  hobama<-het2[12:15,]
  hobamahc<-het1[12:15,]
  hobama$conf.low2<-hobama$estimate-1.645*hobama$std.error
  hobama$conf.high2<-hobama$estimate+1.645*hobama$std.error
  hobamahc$conf.low2<-hobamahc$estimate-1.645*hobamahc$std.error
  hobamahc$conf.high2<-hobamahc$estimate+1.645*hobamahc$std.error
  
  th<-theme(panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            axis.title.x=element_blank(),
            legend.position = c(0.3, 0.85),
            legend.text=element_text(size=7),
            legend.key.size = unit(2, 'mm'),
            plot.title = element_text(size=8,hjust=0.5),
            axis.title.y= element_text(size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=7))
  
  ggplot(data=tobamahc%>%subset(pid!="all"), aes(x=term, y=estimate, shape=pid,color=pid))+ 
    geom_point(aes(),position=position_dodge(0.5),size=3,alpha=1)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c("black","navy","red4"))+
    theme_bw()+
    scale_x_discrete(breaks=c("cond1","cond2","cond3","cond4"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    labs(title="(A) Treatment Effect on Approval of Obama on Healthcare",x="", y = "Difference from Placebo Condition")+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    ylim(-0.2,0.2)+
    th
  ggsave("figs2a.png",width=3.25,height=2.5, dpi = 900)
  
  
  ggplot(data=tobama%>%subset(pid!="all"), aes(x=term, y=estimate,shape=pid,color=pid))+ 
    geom_point(aes(),position=position_dodge(0.5),size=3,alpha=1)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c("black","navy","red4"))+
    theme_bw()+
    scale_x_discrete(breaks=c("cond1","cond2","cond3","cond4"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    labs(title="(B) Treatment Effect on Overall Approval of Obama",x="", y = "Difference from Placebo Condition")+
    ylim(-0.2,0.2)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    th
  ggsave("figs2b.png",width=3.25,height=2.5, dpi = 900)
  
  
  
  ggplot(data=hobamahc, aes(x=term, y=estimate))+ 
    geom_point(aes(),size=3,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_discrete(breaks=c("cond1:dem","cond2:dem","cond3:dem","cond4:dem"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(C) Partisan Difference in Effects on Healthcare Approval",x="", y = "Difference-in-Differences (Dem - Rep)")+
    ylim(-0.2,0.2)+
    annotate(geom="text",x ="cond1:dem", y=c(-0.18,0.18),
             label=c("Negative Diff = Narrowing Partisan Gap",
                     "Positive Diff = Widening Partisan Gap"),
             size=1.8,hjust=0)+  th
  ggsave("figs2c.png",width=3.25,height=2.5, dpi = 900)
  
  
  
  ggplot(data=hobama, aes(x=term, y=estimate))+ 
    geom_point(aes(),size=3,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_discrete(breaks=c("cond1:dem","cond2:dem","cond3:dem","cond4:dem"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(D) Partisan Difference in Effects on Overall Approval",x="", y = "Difference-in-Differences (Dem - Rep)")+
    ylim(-0.2,0.2)+
    annotate(geom="text",x ="cond1:dem", y=c(-0.18,0.18),
             label=c("Negative Diff = Narrowing Partisan Gap",
                     "Positive Diff = Widening Partisan Gap"),
             size=1.8,hjust=0)+  th
  ggsave("figs2d.png",width=3.25,height=2.5, dpi = 900)
  
  # Table S6: Full Regression Estimates of Figure S2 and Robustness Checks #### 
  
  
  m1<-lm(obamahc~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  m2<-lm(obamahc~(cond)*dem,data=subset(aca))
  m3<-lm(obamahc~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1))
  m4<-lm(obamahc~(cond)*dem,data=subset(aca,wgt2==1))
  m5<-lm(obama~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))
  m6<-lm(obama~(cond)*dem,data=subset(aca))
  m7<-lm(obama~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca,wgt2==1))
  m8<-lm(obama~(cond)*dem,data=subset(aca,wgt2==1))
  
  
  
  
  stargazer(m1,m2,m3,m4,m5,m6,m7,m8,
            se=starprep(m1,m2,m3,m4,m5,m6,m7,m8,se_type="HC2"),
            dep.var.labels = c("DV = Obama Healthcare Approval","DV = Obama Overall Approval"),
            covariate.labels = c("Strong Con", "Weak Con", "Weak Pro", "Strong Pro",
                                 "Democrat","Strong Con $\\times$ Dem","Weak Con $\\times$ Dem","Weak Pro $\\times$ Dem", "Strong Pro $\\times$ Dem"),
            star.cutoffs = c(.05, .01, .001),
            keep = c("cond1","cond2","cond3","cond4","dem","Constant"),
            omit = c("w1aca:dem"),
            add.lines = list(c("Covariates","\\checkmark","","\\checkmark","","\\checkmark","","\\checkmark",""),
                             c("Shirkers Dropped","","","\\checkmark","\\checkmark","","","\\checkmark","\\checkmark")),
            #         no.space = TRUE,
            style = "ajps",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  # Table S7: Estimates of Figure S2 in Tabular Form #####  
  
  md<-lm_robust(obamahc~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))%>%tidy()
  mr<-lm_robust(obamahc~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*rep,data=subset(aca))%>%tidy()
  int1<-lm_robust(obamahc~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))%>%
    glht(linfct=c("(cond1:dem+cond2:dem+cond3:dem+cond4:dem)/4=0"))%>%tidy()
  md2<-lm_robust(obama~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))%>%tidy()
  mr2<-lm_robust(obama~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*rep,data=subset(aca))%>%tidy()
  int2<-lm_robust(obama~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*dem,data=subset(aca))%>%
    glht(linfct=c("(cond1:dem+cond2:dem+cond3:dem+cond4:dem)/4=0"))%>%tidy()
  
  col.names<-c("Outcome","Parameter","Definition","Referenc","Coef","SE")
  col1<-c("$\\beta_1$","$\\beta_2$","$\\beta_3$","$\\beta_4$",
          "$\\beta_1+\\delta_1$","$\\beta_2+\\delta_2$","$\\beta_3+\\delta_3$","$\\beta_4+\\delta_4$",
          "$\\delta_1$","$\\delta_2$","$\\delta_3$","$\\delta_4$",
          "$(\\delta_1+\\delta_2+\\delta_3+\\delta_4)/4$")%>%rep(2)
  col2<-c("Strong con effect on Rep","Weak con effect on Rep", "Weak pro effect on Rep", "Strong pro effect on Rep",
          "Strong con effect on Dem","Weak con effect on Dem", "Weak pro effect on Dem", "Strong pro effect on Dem",
          "Partisan difference in strong con effect","Partisan difference in weak con effect", 
          "Partisan difference in weak pro Effect", "Partisan difference in strong pro effect",
          "Average of partisan differences across conditions")%>%rep(2)
  
  
  
  tab.s1<-bind_cols(x=rep(NA,26),y=rep(NA,26),z=rep(NA,26),k=rep(NA,26),
                    bind_rows(md[2:5,2:3],mr[2:5,2:3],md[12:15,2:3],int1[,c(3,4)],
                              md2[2:5,2:3],mr2[2:5,2:3],md2[12:15,2:3],int2[,c(3,4)]))%>%tibble()
  names(tab.s1)<-col.names
  tab.s1[1]<-c(rep("Health",13),rep("Obama",13))
  tab.s1[2]<-col1
  tab.s1[3]<-col2
  tab.s1[4]<-c("Fig \\ref{s1-down}A"%>%rep(4),"Fig \\ref{s1-down}A"%>%rep(4),"Fig \\ref{s1-down}C"%>%rep(4),"",
               "Fig \\ref{s1-down}B"%>%rep(4),"Fig \\ref{s1-down}B"%>%rep(4),"Fig \\ref{s1-down}D"%>%rep(4),"")
  print(xtable(tab.s1),sanitize.text.function=function(x){x}, include.rownames=F,sanitize.colnames.function=bold)
  
  
  
  # Figure S3: Similarities and Differences in Partisans’ Evaluative Criteria ----
  
  
  imp1<-lm(w1costimportant~dem,data=aca)
  imp2<-lm(w1qualityimportant~dem,data=aca)
  imp3<-lm(w1accessimportant~dem,data=aca)
  imp4<-lm(w1governmentimportant	~dem,data=aca)
  
  
  
  stargazer(imp1,imp2,imp3,imp4,
            se=starprep(imp1,imp2,imp3,imp4,se_type="HC2"),
            dep.var.labels = c('\\shortstack{Healthcare \\\\ Costs}',
                               '\\shortstack{Healthcare \\\\ Quality}',
                               '\\shortstack{Equal \\\\ Access}',
                               '\\shortstack{Gov \\\\ Involvement}'),
            covariate.labels = c("Democrat"),
            star.cutoffs = c(.05, .01, .005),
            style = "ajps",
            notes = "ddd",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  imp1<-lm_robust(w1costimportant~dem,data=aca)%>%tidy()
  imp2<-lm_robust(w1qualityimportant~dem,data=aca)%>%tidy()
  imp3<-lm_robust(w1accessimportant~dem,data=aca)%>%tidy()
  imp4<-lm_robust(w1governmentimportant	~dem,data=aca)%>%tidy()
  imp1r<-lm_robust(w1costimportant~rep,data=aca)%>%tidy()
  imp2r<-lm_robust(w1qualityimportant~rep,data=aca)%>%tidy()
  imp3r<-lm_robust(w1accessimportant~rep,data=aca)%>%tidy()
  imp4r<-lm_robust(w1governmentimportant	~rep,data=aca)%>%tidy()
  
  imp<-bind_rows(
    imp1[1,],imp2[1,],imp3[1,],imp4[1,],
    imp1r[1,],imp2r[1,],imp3r[1,],imp4r[1,],
    imp1[2,],imp2[2,],imp3[2,],imp4[2,]
  )
  
  imp$pid<-c(rep("rep",4),rep("dem",4),rep("all",4))
  imp$term<-rep(c(1,2,3,4),3)
  
  
  ggplot(data=subset(imp,pid!="all"), aes(x=term, y=estimate,shape=pid,color=pid))+ 
    geom_point(aes(),size=3,alpha=1,position=position_dodge(0.5))+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","rep","dem"),
                       labels = c("All", "Republicans","Democrats"),
                       values=c(15,17, 16))+
    scale_color_manual(name = c(""),
                       breaks=c("all","rep","dem"),
                       labels = c("All", "Republicans","Democrats"),
                       values=c("black","red4","navy"))+
    theme_bw()+
    scale_x_continuous(breaks=c(1,2,3,4),
                       labels=c("Healthcare\nCosts","Healthcare\nQuality","Equall\nAccess","Government\nInvolvement"))+
    theme(text=element_text(size=9))+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high), size=0.2,position=position_dodge(0.5))+
    labs(title="Importance of Healthcare-Related Considerations",x="", y = "Marginal Means")+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    th+theme(legend.position = c(0.25, 0.15))
  ggsave("figs3a.png",width=3.25,height=2.5, dpi = 900)
  
  
  
  ggplot(data=subset(imp,pid=="all"), aes(x=term, y=estimate))+ 
    geom_point(aes(),size=3,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_continuous(breaks=c(1,2,3,4),
                       labels=c("Healthcare \n Costs","Healthcare \n Quality","Equall \n Access","Government \n Involvement"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="Partisan Difference in Considerations",x="", y = "Difference (Dem - Rep)")+
    annotate(geom="text",x =2.5, y=c(-0.25,0.25),
             label=c("Negative Diff = Considered More Important by Republicans",
                     "Positive Diff = Considered More Important by Democrats"),
             size=1.8,hjust=.5)+
    th
  ggsave("figs3b.png",width=3.25,height=2.5, dpi = 900)
  
  
  
  
  # Table S8: Full Regression Estimates of Figure S3 ----
  imp1<-lm(w1costimportant~dem,data=aca)
  imp2<-lm(w1qualityimportant~dem,data=aca)
  imp3<-lm(w1accessimportant~dem,data=aca)
  imp4<-lm(w1governmentimportant	~dem,data=aca)
  
  
  
  
  
  stargazer(imp1,imp2,imp3,imp4,
            se=starprep(imp1,imp2,imp3,imp4,se_type="HC2"),
            dep.var.labels = c('\\shortstack{Healthcare \\\\ Costs}',
                               '\\shortstack{Healthcare \\\\ Quality}',
                               '\\shortstack{Equal \\\\ Access}',
                               '\\shortstack{Gov \\\\ Involvement}'),
            covariate.labels = c("Democrat"),
            star.cutoffs = c(.05, .01, .005),
            style = "ajps",
            notes = "ddd",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  # Table S9: Average Treatment Effects on Attitude and Belief #### 
  
  
  
  m1<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc),data=subset(aca))
  m2<-lm(aca~(cond),data=subset(aca))
  m3<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc),data=subset(aca,wgt2==1))
  m4<-lm(aca~(cond),data=subset(aca,wgt2==1))
  m5<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc),data=subset(aca))
  m6<-lm(cost~(cond),data=subset(aca))
  m7<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc),data=subset(aca,wgt2==1))
  m8<-lm(cost~(cond),data=subset(aca,wgt2==1))
  
  
  
  stargazer(m1,m2,m3,m4,m5,m6,m7,m8,
            se=starprep(m1,m2,m3,m4,m5,m6,m7,m8,se_type="HC2"),
            dep.var.labels = c("DV = Attitude toward the ACA","DV = Belief that ACA Saves Healthcare Costs"),
            covariate.labels = c("Strong Con", "Weak Con", "Weak Pro", "Strong Pro",
                                 "W1 Attitude", "W1 Belief", "W1 PID Cont.", "W1 Obama", "W1 Obama HC"),
            star.cutoffs = c(.05, .01, .001),
            add.lines = list(
              c("Covariates","\\checkmark","","\\checkmark","","\\checkmark","","\\checkmark",""),
              c("Shirkers Dropped","","","\\checkmark","\\checkmark","","","\\checkmark","\\checkmark")),
            #         no.space = TRUE,
            style = "ajps",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  
  # Table S10: Sample Characteristics of Study 1 vs. 2016 ANES ----------
  
  
  vals <- tibble(
    variables = c("Total N", "Age","","","Gender","","Race","","Education","",
                  "Income","","Social Class", "", "Insured","",
                  "PID","","","","","","",
                  "PID (Binary)","",
                  "PID Strength","",
                  "ACA Support", ""),
    values = c(
      "", "25 or younger (%)","26 to 44 (%)",  "45 or older (%)", 
      "Men (%)", "Women (%)","None White (%)", "White (%)", "No BA Degree (%)", "BA Degree (%)",
      "Below 50K (%)", "Above 50k (%)", "Lower or Working Class (%)", "Middle or Uppder Class (%)",
      "No (%)", "Yes (%)",
      "Strong Rep (%)", "Moderate Rep (%)", "Leaning Rep (%)", "Pure Independent (%)", "Leaning Dem (%)", "Moderate Dem (%)", "Strong Dem (%)",
      "Republican (Combined) (%)", "Democrat (Combined) (%)",
      "Independent/Moderate (%)","Strong Partisan (%)",
      "No (%)","Yes (%)"))
  
  anes.desc<-
    tibble(raw.prc = anes%>%nrow())%>%
    rbind(anes%>%filter(!is.na(age3))%>%frq(age3, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes%>%filter(!is.na(female))%>%frq(female, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes%>%filter(!is.na(white))%>%frq(white, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes%>%filter(!is.na(educ2))%>%frq(educ2, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes%>%filter(!is.na(income))%>%frq(income, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes%>%filter(!is.na(class))%>%frq(class, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes%>%filter(!is.na(insurance))%>%frq(insurance, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes%>%filter(!is.na(pid7))%>%frq(pid7, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes%>%frq(pid3, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc)%>%slice(-2))%>%
    rbind(anes%>%filter(!is.na(str))%>%frq(str, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes%>%filter(!is.na(support))%>%frq(support, weights = V160101, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rename(anes = raw.prc)
  
  
  aca.desc<-tibble(raw.prc = aca%>%filter(!is.na(cond))%>%nrow())%>%
    rbind(aca%>%filter(!is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(educ))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(class))%>%frq(class,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(insurance))%>%frq(insurance,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(pid7))%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca%>%filter(!is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rename(aca.all = raw.prc)%>%
    cbind(
      tibble(raw.prc = aca%>%filter(cond=="1")%>%nrow())%>%
        rbind(aca%>%filter(cond=="1" & !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(class))%>%frq(class,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(insurance))%>%frq(insurance,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(pid7) )%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="1"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca.1 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca%>%filter(cond=="2")%>%nrow())%>%
        rbind(aca%>%filter(cond=="2"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2"& !is.na(class))%>%frq(class,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2"& !is.na(insurance))%>%frq(insurance,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2" & !is.na(pid7))%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="2"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca.2 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca%>%filter(cond=="3")%>%nrow())%>%
        rbind(aca%>%filter(cond=="3"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3"& !is.na(class))%>%frq(class,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3"& !is.na(insurance))%>%frq(insurance,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3" & !is.na(pid7))%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="3"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca.3 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca%>%filter(cond=="4")%>%nrow())%>%
        rbind(aca%>%filter(cond=="4"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4"& !is.na(class))%>%frq(class,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4"& !is.na(insurance))%>%frq(insurance,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4" & !is.na(pid7))%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="4"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca.4 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca%>%filter(cond=="0")%>%nrow())%>%
        rbind(aca%>%filter(cond=="0"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(class))%>%frq(class,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(insurance))%>%frq(insurance,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(pid7) )%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca%>%filter(cond=="0"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca.5 = raw.prc)
    )%>%tibble()
  
  
  study1.desc<-cbind(vals, anes.desc, aca.desc)
  table.study1.desc<-study1.desc
  names(table.study1.desc) <- c("", "Categories", "ANES", "Study 1", "Str C", "Wk C", "Wk P", "Str P","Control")
  table.study1.desc%>%data.frame%>%xtable(digits = 0, align = "rllccccccc")%>%print(include.rownames = FALSE)
  
  # Table S11: Heterogeneous Effects on ACA Attitude by Individual Characteristics (1/2) ----------
  
  
  aca$mod<-case_when(
    aca$age3 == 0 ~ 1,
    aca$age3 == 1 ~ 0
  )
  
  a<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  b<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-case_when(
    aca$age3 == 2 ~ 1,
    aca$age3 == 1 ~ 0
  )
  
  A<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  B<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-aca$female
  
  c<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  d<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-aca$white
  
  e<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  f<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-aca$educ2
  
  g<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  h<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  att_models1 <- list(a,b,A,B,c,d,e,f,g,h)
  
  # rows 1 to 4 (marginal effect when mod = 0) & rows 9 or higher (interaction terms) 
  
  stargazer(a,b,A,B,c,d,e,f,g,h, 
            se=starprep(a,b,A,B,c,d,e,f,g,h,se_type="HC2"),
            order = c(1,2,3,4,11,12,13,14,10),
            omit = c ("w1aca", "w1cost", "pid", "w1obama", "w1obamahc"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            covariate.labels = c("Strong Con (Mod = 0)", "Weak Con (Mod = 0)", 
                                 "Weak Pro (Mod = 0)", "Strong Pro (Mod = 0)",
                                 "Strong Con $\\times$ Mod","Weak Con $\\times$ Mod",
                                 "Weak Pro $\\times$ Mod", "Strong Pro $\\times$ Mod",
                                 "Moderator"
            ),
            star.cutoffs = c(.05),
            add.lines = list(
              c("Sample","Rep", "Dem","Rep","Dem","Rep","Dem","Rep","Dem","Rep","Dem","Rep","Dem"),
              c("Moderator","Age","Age","Age","Age","Women","Women","White","White","B.A.", "B.A."),
              c("","25-","25-","45+","45+","","","","","","")                          
            ), 
            no.space = TRUE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2, digits.extra = 0, keep.stat = c("n"))
  
  
  aca$mod<-case_when(
    aca$age3 == 0 ~ 0,
    aca$age3 == 1 ~ 1
  )
  
  a<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  b<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-case_when(
    aca$age3 == 2 ~ 0,
    aca$age3 == 1 ~ 1
  )
  
  
  A<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  B<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-1-aca$female
  
  c<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  d<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  
  aca$mod<-1-aca$white
  
  e<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  f<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-1-aca$educ2
  
  g<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  h<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  # rows 5 to 8 (marginal effects when mod =1, calculated by flipping each moderator); the table in appendix was created by inserting these rows to the previous stargazer output 
  
  stargazer(a,b,A,B,c,d,e,f,g,h, 
            se=starprep(a,b,A,B,c,d,e,f,g,h,se_type="HC2"),
            order = c(1,2,3,4,11,12,13,14,10),
            omit = c ("w1aca", "w1cost", "pid", "w1obama", "w1obamahc"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            covariate.labels = c("Strong Con (Mod = 1)", "Weak Con (Mod = 1)", 
                                 "Weak Pro (Mod = 1)", "Strong Pro (Mod = 1)",
                                 "Strong Con $\\times$ Mod","Weak Con $\\times$ Mod",
                                 "Weak Pro $\\times$ Mod", "Strong Pro $\\times$ Mod",
                                 "Moderator"
            ),
            star.cutoffs = c(.05),
            add.lines = list(
              c("Sample","Rep", "Dem","Rep","Dem","Rep","Dem","Rep","Dem","Rep","Dem","Rep","Dem"),
              c("Moderator","Age","Age","Age","Age","Women","Women","White","White","B.A.", "B.A."),
              c("","25-","25-","45+","45+","","","","","","")                          
            ), 
            no.space = TRUE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2, digits.extra = 0, keep.stat = c("n"))
  
  
  
  # Table S12: Heterogeneous Effects on ACA Attitude by Individual Characteristics (2/2) ----------
  
  aca$mod<-aca$income
  i<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  j<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-aca$class
  a<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  b<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-aca$insurance
  c<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  d<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-aca$str
  e<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  f<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-aca$support
  g<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  h<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  att_models2 <- list(i,j,a,b,c,d,e,f,g,h)
  
  # rows 1 to 4 (marginal effect when mod = 0) & rows 9 or higher (interaction terms) 
  
  stargazer(i,j,a,b,c,d,e,f,g,h, 
            se=starprep(i,j,a,b,c,d,e,f,g,h,se_type="HC2"),
            order = c(1,2,3,4,11,12,13,14,10),
            omit = c ("w1aca", "w1cost", "pid", "w1obama", "w1obamahc"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            covariate.labels = c("Strong Con (Mod = 0)", "Weak Con (Mod = 0)", 
                                 "Weak Pro (Mod = 0)", "Strong Pro (Mod = 0)",
                                 "Strong Con $\\times$ Mod","Weak Con $\\times$ Mod",
                                 "Weak Pro $\\times$ Mod", "Strong Pro $\\times$ Mod",
                                 "Moderator"
            ),
            star.cutoffs = c(.05),
            add.lines = list(
              c("Sample",rep(c("Rep","Dem"),5)),
              c("Moderator","Earn","Earn","Mid/Up","Mid/Up", "Insured","Insured", "Strong","Strong", "ACA", "ACA"),
              c("","50K+","50K+", "Class","Class","","","PID","PID","Support","Support")                      
            ), 
            no.space = TRUE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2, digits.extra = 0, keep.stat = c("n"))
  
  
  aca$mod<-1-aca$income
  i<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  j<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-1-aca$class
  a<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  b<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-1-aca$insurance
  c<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  d<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-1-aca$str
  e<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  f<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-1-aca$support
  g<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  h<-lm(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  # rows 5 to 8 (marginal effects when mod =1, calculated by flipping each moderator); the table in appendix was created by inserting these rows to the previous stargazer output 
  
  stargazer(i,j,a,b,c,d,e,f,g,h,
            se=starprep(i,j,a,b,c,d,e,f,g,h,se_type="HC2"),
            order = c(1,2,3,4,11,12,13,14,10),
            omit = c ("w1aca", "w1cost", "pid", "w1obama", "w1obamahc"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            covariate.labels = c("Strong Con (Mod = 1)", "Weak Con (Mod = 1)", 
                                 "Weak Pro (Mod = 1)", "Strong Pro (Mod = 1)",
                                 "Strong Con $\\times$ Mod","Weak Con $\\times$ Mod",
                                 "Weak Pro $\\times$ Mod", "Strong Pro $\\times$ Mod",
                                 "Moderator"
            ),
            star.cutoffs = c(.05),
            add.lines = list(
              c("Sample",rep(c("Rep","Dem"),5)),
              c("Moderator","Earn","Earn","Mid/Up","Mid/Up", "Insured","Insured", "Strong","Strong", "ACA", "ACA"),
              c("","50K+","50K+", "Class","Class","","","PID","PID","Support","Support")                      
            ), 
            no.space = TRUE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2, digits.extra = 0, keep.stat = c("n"))
  
  
  # counting significant p-values in Tables S11 and S12
  
  ps1<-bind_rows(lapply(att_models1, tidy),lapply(att_models1, tidy))%>%
    filter(term == "cond1:mod"|term == "cond2:mod"|term == "cond3:mod"|term == "cond4:mod")%>%
    pull(p.value)
  
  sum(ps1<.05)
  sum(ps1<.05)/length(ps1)
  
  # Table S13: Heterogeneous Effects on Cost Belief by Individual Characteristics (1/2) ----------
  
  
  aca$mod<-case_when(
    aca$age3 == 0 ~ 1,
    aca$age3 == 1 ~ 0
  )
  
  a<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  b<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-case_when(
    aca$age3 == 2 ~ 1,
    aca$age3 == 1 ~ 0
  )
  
  A<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  B<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-aca$female
  
  c<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  d<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-aca$white
  
  e<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  f<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-aca$educ2
  
  g<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  h<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  bel_models1 <- list(a,b,A,B,c,d,e,f,g,h)
  
  # rows 1 to 4 (marginal effect when mod = 0) & rows 9 or higher (interaction terms) 
  
  stargazer(a,b,A,B,c,d,e,f,g,h, 
            se=starprep(a,b,A,B,c,d,e,f,g,h,se_type="HC2"),
            order = c(1,2,3,4,11,12,13,14,10),
            omit = c ("w1aca", "w1cost", "pid", "w1obama", "w1obamahc"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            covariate.labels = c("Strong Con (Mod = 0)", "Weak Con (Mod = 0)", 
                                 "Weak Pro (Mod = 0)", "Strong Pro (Mod = 0)",
                                 "Strong Con $\\times$ Mod","Weak Con $\\times$ Mod",
                                 "Weak Pro $\\times$ Mod", "Strong Pro $\\times$ Mod",
                                 "Moderator"
            ),
            star.cutoffs = c(.05),
            add.lines = list(
              c("Sample","Rep", "Dem","Rep","Dem","Rep","Dem","Rep","Dem","Rep","Dem","Rep","Dem"),
              c("Moderator","Age","Age","Age","Age","Women","Women","White","White","B.A.", "B.A."),
              c("","25-","25-","45+","45+","","","","","","")                          
            ), 
            no.space = TRUE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2, digits.extra = 0, keep.stat = c("n"))
  
  
  
  aca$mod<-case_when(
    aca$age3 == 0 ~ 0,
    aca$age3 == 1 ~ 1
  )
  
  a<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  b<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-case_when(
    aca$age3 == 2 ~ 0,
    aca$age3 == 1 ~ 1
  )
  
  
  A<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  B<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-1-aca$female
  
  c<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  d<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  
  aca$mod<-1-aca$white
  
  e<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  f<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-1-aca$educ2
  
  g<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  h<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  # rows 5 to 8 (marginal effects when mod =1, calculated by flipping each moderator); the table in appendix was created by inserting these rows to the previous stargazer output 
  
  stargazer(a,b,A,B,c,d,e,f,g,h, 
            se=starprep(a,b,A,B,c,d,e,f,g,h,se_type="HC2"),
            order = c(1,2,3,4,11,12,13,14,10),
            omit = c ("w1aca", "w1cost", "pid", "w1obama", "w1obamahc"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            covariate.labels = c("Strong Con (Mod = 1)", "Weak Con (Mod = 1)", 
                                 "Weak Pro (Mod = 1)", "Strong Pro (Mod = 1)",
                                 "Strong Con $\\times$ Mod","Weak Con $\\times$ Mod",
                                 "Weak Pro $\\times$ Mod", "Strong Pro $\\times$ Mod",
                                 "Moderator"
            ),
            star.cutoffs = c(.05),
            add.lines = list(
              c("Sample","Rep", "Dem","Rep","Dem","Rep","Dem","Rep","Dem","Rep","Dem","Rep","Dem"),
              c("Moderator","Age","Age","Age","Age","Women","Women","White","White","B.A.", "B.A."),
              c("","25-","25-","45+","45+","","","","","","")                          
            ), 
            no.space = TRUE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2, digits.extra = 0, keep.stat = c("n"))
  
  
  # Table S14: Heterogeneous Effects on Cost Belief by Individual Characteristics (2/2) ----------
  
  aca$mod<-aca$income
  i<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  j<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-aca$class
  a<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  b<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-aca$insurance
  c<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  d<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-aca$str
  e<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  f<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-aca$support
  g<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  h<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  bel_models2 <- list(i,j,a,b,c,d,e,f,g,h)
  
  
  # rows 1 to 4 (marginal effect when mod = 0) & rows 9 or higher (interaction terms) 
  
  stargazer(i,j,a,b,c,d,e,f,g,h,
            se=starprep(i,j,a,b,c,d,e,f,g,h,se_type="HC2"),
            order = c(1,2,3,4,11,12,13,14,10),
            omit = c ("w1aca", "w1cost", "pid", "w1obama", "w1obamahc"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            covariate.labels = c("Strong Con (Mod = 0)", "Weak Con (Mod = 0)", 
                                 "Weak Pro (Mod = 0)", "Strong Pro (Mod = 0)",
                                 "Strong Con $\\times$ Mod","Weak Con $\\times$ Mod",
                                 "Weak Pro $\\times$ Mod", "Strong Pro $\\times$ Mod",
                                 "Moderator"
            ),
            star.cutoffs = c(.05),
            add.lines = list(
              c("Sample",rep(c("Rep","Dem"),5)),
              c("Moderator","Earn","Earn","Mid/Up","Mid/Up", "Insured","Insured", "Strong","Strong", "ACA", "ACA"),
              c("","50K+","50K+", "Class","Class","","","PID","PID","Support","Support")                      
            ), 
            no.space = TRUE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2, digits.extra = 0, keep.stat = c("n"))
  
  
  
  aca$mod<-1-aca$income
  i<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  j<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  
  aca$mod<-1-aca$class
  a<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  b<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-1-aca$insurance
  c<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  d<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-1-aca$str
  e<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  f<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  aca$mod<-1-aca$support
  g<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==0))
  h<-lm(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc)*mod,data=subset(aca, dem==1))
  
  # rows 5 to 8 (marginal effects when mod =1, calculated by flipping each moderator); the table in appendix was created by inserting these rows to the previous stargazer output 
  
  stargazer(i,j,a,b,c,d,e,f,g,h,
            se=starprep(i,j,a,b,c,d,e,f,g,h,se_type="HC2"),
            order = c(1,2,3,4,11,12,13,14,10),
            omit = c ("w1aca", "w1cost", "pid", "w1obama", "w1obamahc"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            covariate.labels = c("Strong Con (Mod = 1)", "Weak Con (Mod = 1)", 
                                 "Weak Pro (Mod = 1)", "Strong Pro (Mod = 1)",
                                 "Strong Con $\\times$ Mod","Weak Con $\\times$ Mod",
                                 "Weak Pro $\\times$ Mod", "Strong Pro $\\times$ Mod",
                                 "Moderator"
            ),
            star.cutoffs = c(.05),
            add.lines = list(
              c("Sample",rep(c("Rep","Dem"),5)),
              c("Moderator","Earn","Earn","Mid/Up","Mid/Up", "Insured","Insured", "Strong","Strong", "ACA", "ACA"),
              c("","50K+","50K+", "Class","Class","","","PID","PID","Support","Support")                      
            ), 
            no.space = TRUE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2, digits.extra = 0, keep.stat = c("n"))
  
  
  # counting significant p-values in Tables S13 and S14
  
  ps2<-bind_rows(lapply(bel_models1, tidy),lapply(bel_models1, tidy))%>%
    filter(term == "cond1:mod"|term == "cond2:mod"|term == "cond3:mod"|term == "cond4:mod")%>%
    pull(p.value)
  
  sum(ps2<.05)
  sum(ps2<.05)/length(ps2)
  
  # Figures S4 and S5 Treatment Effects Weighted by Individual Characteristics ----
  
  # calculating weights study 1 for Figures S4 to S6 
  
  aca<-aca%>%
    mutate(
      w1 = case_when(
        age3 == 0 ~ study1.desc$anes[2]/study1.desc$aca.all[2],
        age3 == 1 ~ study1.desc$anes[3]/study1.desc$aca.all[3],
        age3 == 2 ~ study1.desc$anes[4]/study1.desc$aca.all[4]
      ),
      w2 = case_when(
        female == 0 ~ study1.desc$anes[5]/study1.desc$aca.all[5],
        female == 1 ~ study1.desc$anes[6]/study1.desc$aca.all[6]
      ),
      w3 = case_when(
        white == 0 ~ study1.desc$anes[7]/study1.desc$aca.all[7],
        white == 1 ~ study1.desc$anes[8]/study1.desc$aca.all[8]
      ),
      w4 = case_when(
        educ2 == 0 ~ study1.desc$anes[9]/study1.desc$aca.all[9],
        educ2 == 1 ~ study1.desc$anes[10]/study1.desc$aca.all[10]
      ),
      w5 = case_when(
        income == 0 ~ study1.desc$anes[11]/study1.desc$aca.all[11],
        income == 1 ~ study1.desc$anes[12]/study1.desc$aca.all[12]
      ),
      w6 = case_when(
        class == 0 ~ study1.desc$anes[13]/study1.desc$aca.all[13],
        class == 1 ~ study1.desc$anes[14]/study1.desc$aca.all[14]
      ),
      w7 = case_when(
        insurance == 0 ~ study1.desc$anes[15]/study1.desc$aca.all[15],
        insurance == 1 ~ study1.desc$anes[16]/study1.desc$aca.all[16]
      ),
      w8 = case_when(
        pid7 == 0 ~ study1.desc$anes[17]/study1.desc$aca.all[17],
        pid7 == 1 ~ study1.desc$anes[18]/study1.desc$aca.all[18],
        pid7 == 2 ~ study1.desc$anes[19]/study1.desc$aca.all[19],
        pid7 == 3 ~ study1.desc$anes[20]/study1.desc$aca.all[20],
        pid7 == 4 ~ study1.desc$anes[21]/study1.desc$aca.all[21],
        pid7 == 5 ~ study1.desc$anes[22]/study1.desc$aca.all[22],
        pid7 == 6 ~ study1.desc$anes[23]/study1.desc$aca.all[23]
      ),
      w9 = case_when(
        support == 0 ~ study1.desc$anes[28]/study1.desc$aca.all[28],
        support == 1 ~ study1.desc$anes[29]/study1.desc$aca.all[29]
      )
    )
  
  
  # common theme
  common_theme <- theme_bw() + theme(panel.grid.major=element_blank(),
                                     panel.grid.minor=element_blank(),
                                     panel.border=element_rect(colour="black"),
                                     axis.title.x=element_blank(),
                                     legend.position = c(0.3, 0.85),
                                     legend.background = element_blank(),
                                     legend.text=element_text(size=7),
                                     legend.key.size = unit(2, 'mm'),
                                     plot.title = element_text(size=8,hjust=0.5),
                                     axis.title.y= element_text(size=7),
                                     axis.text.x = element_text(color = "black", size=6),
                                     axis.text.y = element_text(color = "black", size=7))
  
  te_plot <- function(data, title, file_name) {
    p <- ggplot(data = data, aes(x = term, y = estimate, shape = pid, color = pid)) +
      geom_point(position = position_dodge(0.3), size = 2) +
      scale_shape_manual(name = "",
                         breaks = c("dem", "rep"),
                         labels = c("Dem", "Rep"),
                         values = c(16, 17)) +
      scale_color_manual(name = "",
                         breaks = c( "dem", "rep"),
                         labels = c("Dem", "Rep"),
                         values = c("navy", "red4")) +
      scale_x_discrete(breaks = c("cond1", "cond2", "cond3", "cond4"),
                       labels = c("Strong \n Con", "Weak \n Con", "Weak \n Pro", "Strong \n Pro")) +
      geom_hline(yintercept = 0, linetype = "dashed", size = 0.4) +
      geom_linerange(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(0.3), size = 0.4) +
      labs(title = title, x = "", y = "Diff from Placebo") +
      ylim(-0.2, 0.2) +
      guides(shape = guide_legend(title = NULL), color = guide_legend(title = NULL)) +
      common_theme
    
    ggsave(file_name, plot = p, width = 2.1, height = 2)
  }
  
  
  
  aca$w<-1
  
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  te_plot(taca, "A: Unweighted", "figs4a.pdf")
  te_plot(tcost, "A: Unweighted", "figs5a.pdf")
  
  
  
  # age
  
  aca$w<-aca$w1
  
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  te_plot(taca, "B: Weighted by Age", "figs4b.pdf")
  te_plot(tcost, "B: Weighted by Age", "figs5b.pdf")
  
  # gender  
  
  aca$w<-aca$w2
  
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  te_plot(taca, "C: Weighted by Gender", "figs4c.pdf")
  te_plot(tcost, "C: Weighted by Gender", "figs5c.pdf")
  
  
  # race #
  aca$w<-aca$w3
  
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  te_plot(taca, "D: Weighted by Race", "figs4d.pdf")
  te_plot(tcost, "D: Weighted by Race", "figs5d.pdf")
  
  
  # education #
  
  aca$w<-aca$w4
  
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  te_plot(taca, "E: Weighted by Education", "figs4e.pdf")
  te_plot(tcost, "E: Weighted by Education", "figs5e.pdf")
  
  
  # income
  
  
  aca$w<-aca$w5
  
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  te_plot(taca, "F: Weighted by Income", "figs4f.pdf")
  te_plot(tcost, "F: Weighted by Income", "figs5f.pdf")
  
  
  
  # class
  
  aca$w<-aca$w6
  
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  te_plot(taca, "G: Weighted by Class", "figs4g.pdf")
  te_plot(tcost, "G: Weighted by Class", "figs5g.pdf")
  
  
  # insurance 
  
  aca$w<-aca$w7
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  te_plot(taca, "H: Weighted by Health Insurnace", "figs4h.pdf")
  te_plot(tcost, "H: Weighted by Health Insurnace", "figs5h.pdf")
  
  
  
  # pid  
  
  aca$w<-aca$w8
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1),weights = w))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0),weights = w))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  te_plot(taca, "I: Weighted by PID (7-point)", "figs4i.pdf")
  te_plot(tcost, "I: Weighted by PID (7-point)", "figs5i.pdf")
  
  
  # Figure S6: Treatment Effects Weighted by Age ----
  
  aca$w<-aca$w1
  
  # common theme
  common_theme <- theme_bw() + theme(panel.grid.major=element_blank(),
                                     panel.grid.minor=element_blank(),
                                     panel.border=element_rect(colour="black"),
                                     axis.title.x=element_blank(),
                                     legend.position = c(0.3, 0.85),
                                     legend.background = element_blank(),
                                     legend.text=element_text(size=7),
                                     legend.key.size = unit(2, 'mm'),
                                     plot.title = element_text(size=8,hjust=0.5),
                                     axis.title.y= element_text(size=7),
                                     axis.text.x = element_text(color = "black", size=6),
                                     axis.text.y = element_text(color = "black", size=7))
  
  # common plot function
  
  te_plot <- function(data, title, file_name) {
    p <- ggplot(data = data, aes(x = term, y = estimate, shape = pid, color = pid)) +
      geom_point(position = position_dodge(0.3), size = 3) +
      scale_shape_manual(name = "",
                         breaks = c("dem", "rep"),
                         labels = c("Democrats", "Republicans"),
                         values = c(16, 17)) +
      scale_color_manual(name = "",
                         breaks = c( "dem", "rep"),
                         labels = c("Democrats", "Republicans"),
                         values = c("navy", "red4")) +
      scale_x_discrete(breaks = c("cond1", "cond2", "cond3", "cond4"),
                       labels = c("Strong \n Con", "Weak \n Con", "Weak \n Pro", "Strong \n Pro")) +
      geom_hline(yintercept = 0, linetype = "dashed", size = 0.4) +
      geom_linerange(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(0.3), size = 0.4) +
      labs(title = title, x = "", y = "Difference from Placebo Condition") +
      ylim(-0.2, 0.2) +
      guides(shape = guide_legend(title = NULL), color = guide_legend(title = NULL)) +
      common_theme
    ggsave(file_name, plot = p, width = 3.25, height = 1.8)
  }
  
  he_plot <- function(data, title, file_name) {
    p <- ggplot(data = data, aes(x = term, y = estimate)) +
      geom_point(size = 3, shape = 1, stroke = .4) +
      scale_x_discrete(breaks = c("cond1:dem", "cond2:dem", "cond3:dem", "cond4:dem"),
                       labels = c("Strong \n Con", "Weak \n Con", "Weak \n Pro", "Strong \n Pro")) +
      geom_hline(yintercept = 0, linetype = "dashed", size = 0.4) +
      geom_linerange(aes(ymin = conf.low, ymax = conf.high), position = position_dodge(0.5), size = 0.4) +
      labs(title = title, x = "", y = "Diff-in-Diff (Dem - Rep)") +
      ylim(-0.2, 0.2) +
      annotate(geom = "text", x = "cond1:dem", y = c(-0.18, 0.18),
               label = c("Negative Diff = Narrowing Partisan Gap",
                         "Positive Diff = Widening Partisan Gap"),
               size = 1.8, hjust = 0) +
      common_theme
    ggsave(file_name, plot = p, width = 3.25, height = 1.8)
  }
  
  
  
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))
  h1<-tidy(lm_robust(aca~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca)))
  h2<-tidy(lm_robust(cost~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca)))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  hcost<-h2[12:15,]
  haca<-h1[12:15,]
  
  te_plot(taca, "(A1) Effects on Attitude toward ACA (Unweighted)", "figs6a1.pdf")
  he_plot(haca, "(B1) Partisan Difference in Effect on Attitude (Unweighted)", "figs6b1.pdf")
  te_plot(tcost, "(C1) Effects on Belief about Cost (Unweighted)", "figs6c1.pdf")
  he_plot(hcost, "(D1) Partisan Difference in Effect on Belief (Unweighted)", "figs6d1.pdf")
  
  
  m1<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1), weights = w1))
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0), weights = w1))
  m3<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1), weights = w1))
  m4<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0), weights = w1))
  h1<-tidy(lm_robust(aca~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca), weights = w1))
  h2<-tidy(lm_robust(cost~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca), weights = w1))
  
  tcost<-bind_rows(dem=m3[2:5,],rep=m4[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m1[2:5,],rep=m2[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  hcost<-h2[12:15,]
  haca<-h1[12:15,]
  
  
  te_plot(taca, "(A2) Effects on Attitude toward ACA (Weighted by Age)", "fig6a2.pdf")
  he_plot(haca, "(B2) Partisan Diff in Effect on Attitude (Weighted by Age)", "fig6b2.pdf")
  te_plot(tcost, "(C2) Effects on Belief about Cost (Weighted by Age)", "fig6c2.pdf")
  he_plot(hcost, "(D2) Partisan Diff in Effect on Belief (Weighted by Age)", "fig6d2.pdf")
  
  
  
  # Table S15: Study1 randomization check ----
  
  models <- list(
    m1a = aca %>% filter() %>% lm(w1aca ~ cond, data = .),
    m2a = aca %>% filter() %>% lm(w1cost ~ cond, data = .),
    m3a = aca %>% filter() %>% lm(w1obamahc ~ cond, data = .),
    m4a = aca %>% filter() %>% lm(w1obama ~ cond, data = .),
    m5a = aca %>% filter() %>% lm(pid ~ cond, data = .),
    m6a = aca %>% filter() %>% lm(age45 ~ cond, data = .),
    m7a = aca %>% filter() %>% lm(female ~ cond, data = .),
    m8a = aca %>% filter() %>% lm(white ~ cond, data = .),
    m9a = aca %>% filter() %>% lm(educ2 ~ cond, data = .),
    m10a = aca %>% filter() %>% lm(income ~ cond, data = .),
    m11a = aca %>% filter() %>% lm(class ~ cond, data = .),
    m12a = aca %>% filter() %>% lm(insurance ~ cond, data = .),
    m1b =  aca %>% filter(dem == 0) %>% lm(w1aca ~ cond, data =  .),
    m2b =  aca %>% filter(dem == 0) %>% lm(w1cost ~ cond, data =  .),
    m3b =  aca %>% filter(dem == 0) %>% lm(w1obamahc ~ cond, data =  .),
    m4b =  aca %>% filter(dem == 0) %>% lm(w1obama ~ cond, data =  .),
    m5b =  aca %>% filter(dem == 0) %>% lm(pid ~ cond, data =  .),
    m6b =  aca %>% filter(dem == 0) %>% lm(age45 ~ cond, data =  .),
    m7b =  aca %>% filter(dem == 0) %>% lm(female ~ cond, data =  .),
    m8b =  aca %>% filter(dem == 0) %>% lm(white ~ cond, data =  .),
    m9b =  aca %>% filter(dem == 0) %>% lm(educ2 ~ cond, data =  .),
    m10b =  aca %>% filter(dem == 0) %>% lm(income ~ cond, data =  .),
    m11b =  aca %>% filter(dem == 0) %>% lm(class ~ cond, data =  .),
    m12b =  aca %>% filter(dem == 0) %>% lm(insurance ~ cond, data =  .),
    m1c = aca %>% filter(dem == 1) %>% lm(w1aca ~ cond, data = .),
    m2c = aca %>% filter(dem == 1) %>% lm(w1cost ~ cond, data = .),
    m3c = aca %>% filter(dem == 1) %>% lm(w1obamahc ~ cond, data = .),
    m4c = aca %>% filter(dem == 1) %>% lm(w1obama ~ cond, data = .),
    m5c = aca %>% filter(dem == 1) %>% lm(pid ~ cond, data = .),
    m6c = aca %>% filter(dem == 1) %>% lm(age45 ~ cond, data = .),
    m7c = aca %>% filter(dem == 1) %>% lm(female ~ cond, data = .),
    m8c = aca %>% filter(dem == 1) %>% lm(white ~ cond, data = .),
    m9c = aca %>% filter(dem == 1) %>% lm(educ2 ~ cond, data = .),
    m10c = aca %>% filter(dem == 1) %>% lm(income ~ cond, data = .),
    m11c = aca %>% filter(dem == 1) %>% lm(class ~ cond, data = .),
    m12c = aca %>% filter(dem == 1) %>% lm(insurance ~ cond, data = .)
  )
  
  
  models.hc2 <- list(
    m1a = aca %>% filter() %>% lm_robust(w1aca ~ cond, data = .),
    m2a = aca %>% filter() %>% lm_robust(w1cost ~ cond, data = .),
    m3a = aca %>% filter() %>% lm_robust(w1obamahc ~ cond, data = .),
    m4a = aca %>% filter() %>% lm_robust(w1obama ~ cond, data = .),
    m5a = aca %>% filter() %>% lm_robust(pid ~ cond, data = .),
    m6a = aca %>% filter() %>% lm_robust(age45 ~ cond, data = .),
    m7a = aca %>% filter() %>% lm_robust(female ~ cond, data = .),
    m8a = aca %>% filter() %>% lm_robust(white ~ cond, data = .),
    m9a = aca %>% filter() %>% lm_robust(educ2 ~ cond, data = .),
    m10a = aca %>% filter() %>% lm_robust(income ~ cond, data = .),
    m11a = aca %>% filter() %>% lm_robust(class ~ cond, data = .),
    m12a = aca %>% filter() %>% lm_robust(insurance ~ cond, data = .),
    m1b =  aca %>% filter(dem == 0) %>% lm_robust(w1aca ~ cond, data =  .),
    m2b =  aca %>% filter(dem == 0) %>% lm_robust(w1cost ~ cond, data =  .),
    m3b =  aca %>% filter(dem == 0) %>% lm_robust(w1obamahc ~ cond, data =  .),
    m4b =  aca %>% filter(dem == 0) %>% lm_robust(w1obama ~ cond, data =  .),
    m5b =  aca %>% filter(dem == 0) %>% lm_robust(pid ~ cond, data =  .),
    m6b =  aca %>% filter(dem == 0) %>% lm_robust(age45 ~ cond, data =  .),
    m7b =  aca %>% filter(dem == 0) %>% lm_robust(female ~ cond, data =  .),
    m8b =  aca %>% filter(dem == 0) %>% lm_robust(white ~ cond, data =  .),
    m9b =  aca %>% filter(dem == 0) %>% lm_robust(educ2 ~ cond, data =  .),
    m10b =  aca %>% filter(dem == 0) %>% lm_robust(income ~ cond, data =  .),
    m11b =  aca %>% filter(dem == 0) %>% lm_robust(class ~ cond, data =  .),
    m12b =  aca %>% filter(dem == 0) %>% lm_robust(insurance ~ cond, data =  .),
    m1c = aca %>% filter(dem == 1) %>% lm_robust(w1aca ~ cond, data = .),
    m2c = aca %>% filter(dem == 1) %>% lm_robust(w1cost ~ cond, data = .),
    m3c = aca %>% filter(dem == 1) %>% lm_robust(w1obamahc ~ cond, data = .),
    m4c = aca %>% filter(dem == 1) %>% lm_robust(w1obama ~ cond, data = .),
    m5c = aca %>% filter(dem == 1) %>% lm_robust(pid ~ cond, data = .),
    m6c = aca %>% filter(dem == 1) %>% lm_robust(age45 ~ cond, data = .),
    m7c = aca %>% filter(dem == 1) %>% lm_robust(female ~ cond, data = .),
    m8c = aca %>% filter(dem == 1) %>% lm_robust(white ~ cond, data = .),
    m9c = aca %>% filter(dem == 1) %>% lm_robust(educ2 ~ cond, data = .),
    m10c = aca %>% filter(dem == 1) %>% lm_robust(income ~ cond, data = .),
    m11c = aca %>% filter(dem == 1) %>% lm_robust(class ~ cond, data = .),
    m12c = aca %>% filter(dem == 1) %>% lm_robust(insurance ~ cond, data = .)
  )
  
  est <- lapply(names(models.hc2), function(name) {
    model <- models.hc2[[name]]
    tidy_model <- tidy(model)
    tidy_model$model <- name
    return(tidy_model)
  })%>%bind_rows()%>%
    filter(term!="(Intercept)")
  
  
  # Extracting F-statistics and their p-values
  f_stats <- sapply(models.hc2, function(m) sprintf("%.2f", glance(m)$statistic))
  f_p_values <- sapply(models.hc2, function(m) sprintf("%.2f", glance(m)$p.value))
  
  
  # Adding F-statistics and p-values as custom lines to stargazer output
  stargazer(models[1:12], 
            se=starprep(
              models[1:12]
            ),se_type="HC2",
            digits= 2, digits.extra = 0, keep.stat = c("n"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            star.cutoffs = c(.05),
            column.sep.width = "5pt",
            style = "apsr",
            covariate.labels = c("Strong Con", "Weak Con", "Weak Pro", "Strong Pro"),
            add.lines = list(
              c("F (DF1 = 4)", f_stats),
              c("P-value", f_p_values),
              c("Panel A", "Pre-", "Pre-", "Obama", "Obama", "PID", "Age", "Women", "White", "B.A.", "Earn", "Mid/Up", "Insured"),
              c("All","Atti", "Belief", "HCare", "Overall", "", "45+", "", "","", "50K+", "Class", "")
            ))
  
  
  stargazer(models[13:24], 
            se=starprep(
              models[13:24]
            ),se_type="HC2",
            digits= 2, digits.extra = 0, keep.stat = c("n"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            star.cutoffs = c(.05),
            column.sep.width = "5pt",
            style = "apsr",
            covariate.labels = c("Strong Con", "Weak Con", "Weak Pro", "Strong Pro"),
            add.lines = list(
              c("F (DF1 = 4)", f_stats[13:24]),
              c("P-value", f_p_values[13:24]),
              c("Panel B", "Pre-", "Pre-", "Obama", "Obama", "PID", "Age", "Women", "White", "B.A.", "Earn", "Mid/Up", "Insured"),
              c("Republican","Atti", "Belief", "HCare", "Overall", "PID", "45+", "", "","", "50K+", "Class", "")
            ))
  
  
  stargazer(models[25:36], 
            se=starprep(
              models[25:36]
            ),se_type="HC2",
            digits= 2, digits.extra = 0, keep.stat = c("n"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            star.cutoffs = c(.05),
            column.sep.width = "5pt",
            style = "apsr",
            covariate.labels = c("Strong Con", "Weak Con", "Weak Pro", "Strong Pro"),
            add.lines = list(
              c("F (DF1 = 4)", f_stats[25:36]),
              c("P-value", f_p_values[25:36]),
              c("Panel C", "Pre-", "Pre-", "Obama", "Obama", "PID", "Age", "Women", "White", "B.A.", "Earn", "Mid/Up", "Insured"),
              c("Democrat","Atti", "Belief", "HCare", "Overall", "", "45+", "", "","", "50K+", "Class", "")
            ))
  
  # counting p-values in Table S15
  sum(est$p.value < 0.05)
  sum(p.adjust(est$p.value, method = "holm") < 0.05)
  
  
  
  # Table S16 Study 1 Joint Test of Balance ----
  
  aca.dem<- aca%>%
    filter(!is.na(w1aca) & 
             !is.na(w1cost) & 
             !is.na(w1obamahc) & 
             !is.na(w1obama) & 
             !is.na(pid) & 
             !is.na(age45) & 
             !is.na(female) & 
             !is.na(white) & 
             !is.na(educ2) & 
             !is.na(income) & 
             !is.na(class) & 
             !is.na(insurance) & 
             dem == 1)
  
  aca.rep<- aca%>%
    filter(!is.na(w1aca) & 
             !is.na(w1cost) & 
             !is.na(w1obamahc) & 
             !is.na(w1obama) & 
             !is.na(pid) & 
             !is.na(age45) & 
             !is.na(female) & 
             !is.na(white) & 
             !is.na(educ2) & 
             !is.na(income) & 
             !is.na(class) & 
             !is.na(insurance) & 
             dem == 0)
  
  aca.all<- aca%>%
    filter(!is.na(w1aca) & 
             !is.na(w1cost) & 
             !is.na(w1obamahc) & 
             !is.na(w1obama) & 
             !is.na(pid) & 
             !is.na(age45) & 
             !is.na(female) & 
             !is.na(white) & 
             !is.na(educ2) & 
             !is.na(income) & 
             !is.na(class) & 
             !is.na(insurance))
  
  aca.all.w3<- aca.all%>%
    filter(wave3 ==1)
  
  aca.all.w4<- aca.all%>%
    filter(wave4 ==1)
  
  aca.dem.w3<- aca.dem%>%
    filter(wave3 ==1)
  
  aca.dem.w4<- aca.dem%>%
    filter(wave4 ==1)
  
  aca.rep.w3<- aca.rep%>%
    filter(wave3 ==1)
  
  aca.rep.w4<- aca.rep%>%
    filter(wave4 ==1)
  
  
  joint_tests<-bind_rows(
    multinom(factor(cond)~ w1aca + w1cost+w1obamahc+w1obama+pid+age45+female+white+educ2+income+class+insurance, data = aca.all)%>%lrtest()%>%tidy(),
    multinom(factor(cond)~ w1aca + w1cost+w1obamahc+w1obama+pid+age45+female+white+educ2+income+class+insurance, data = aca.rep)%>%lrtest()%>%tidy(),
    multinom(factor(cond)~ w1aca + w1cost+w1obamahc+w1obama+pid+age45+female+white+educ2+income+class+insurance, data = aca.dem)%>%lrtest()%>%tidy(),
    multinom(factor(cond)~ w1aca + w1cost+w1obamahc+w1obama+pid+age45+female+white+educ2+income+class+insurance, data = aca.all.w3)%>%lrtest()%>%tidy(),
    multinom(factor(cond)~ w1aca + w1cost+w1obamahc+w1obama+pid+age45+female+white+educ2+income+class+insurance, data = aca.rep.w3)%>%lrtest()%>%tidy(),
    multinom(factor(cond)~ w1aca + w1cost+w1obamahc+w1obama+pid+age45+female+white+educ2+income+class+insurance, data = aca.dem.w3)%>%lrtest()%>%tidy(),
    multinom(factor(cond)~ w1aca + w1cost+w1obamahc+w1obama+pid+age45+female+white+educ2+income+class+insurance, data = aca.all.w4)%>%lrtest()%>%tidy(),
    multinom(factor(cond)~ w1aca + w1cost+w1obamahc+w1obama+pid+age45+female+white+educ2+income+class+insurance, data = aca.rep.w4)%>%lrtest()%>%tidy(),
    multinom(factor(cond)~ w1aca + w1cost+w1obamahc+w1obama+pid+age45+female+white+educ2+income+class+insurance, data = aca.dem.w4)%>%lrtest()%>%tidy()
  )%>%
    filter(term=="factor(cond) ~ 1")%>%
    mutate(chi.squred = statistic,
           sample = rep(c("All","Republicans","Democrats"),3),
           wave = c(2,2,2,3,3,3,4,4,4))%>%
    select(wave,sample,chi.squred,p.value)%>%
    setNames(c("Wave", "Sample","Chi-Squared (48)", "P-Value"))
  
  
  xtable(joint_tests, digits = c(0,0,0,1,3), align = "lllcc")%>%print(include.rownames = F)
  
  
  
  # Table S17 Outcome Variable Means ----------
  
  
  
  a16<-aca%>%filter(!is.na(cond))
  
  m1<-lm(aca~cond,data=subset(a16))
  m2<-lm(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(a16))
  m3<-lm(aca~cond,data=subset(a16,dem==0))
  m4<-lm(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(a16,dem==0))
  m5<-lm(aca~cond,data=subset(a16,dem==1))
  m6<-lm(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(a16,dem==1))
  
  m7<-lm(cost~cond,data=subset(a16))
  m8<-lm(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(a16))
  m9<-lm(cost~cond,data=subset(a16,dem==0))
  m10<-lm(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(a16,dem==0))
  m11<-lm(cost~cond,data=subset(a16,dem==1))
  m12<-lm(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(a16,dem==1))
  
  
  ###Estimated means by condition and pid
  p1<-summary(prediction(m1, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m1),calculate_se = TRUE))
  p2<-summary(prediction(m2, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m2),calculate_se = TRUE))
  p3<-summary(prediction(m3, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m3),calculate_se = TRUE))
  p4<-summary(prediction(m4, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m4),calculate_se = TRUE))
  p5<-summary(prediction(m5, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m5),calculate_se = TRUE))
  p6<-summary(prediction(m6, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m6),calculate_se = TRUE))
  p7<-summary(prediction(m7, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m1),calculate_se = TRUE))
  p8<-summary(prediction(m8, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m2),calculate_se = TRUE))
  p9<-summary(prediction(m9, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m3),calculate_se = TRUE))
  p10<-summary(prediction(m10, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m4),calculate_se = TRUE))
  p11<-summary(prediction(m11, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m5),calculate_se = TRUE))
  p12<-summary(prediction(m12, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m6),calculate_se = TRUE))
  
  c1<-p1%>%select(Prediction, SE)
  c2<-p2%>%select(Prediction, SE)
  c3<-p3%>%select(Prediction, SE)
  c4<-p4%>%select(Prediction, SE)
  c5<-p5%>%select(Prediction, SE)
  c6<-p6%>%select(Prediction, SE)
  
  c7<-p7%>%select(Prediction, SE)
  c8<-p8%>%select(Prediction, SE)
  c9<-p9%>%select(Prediction, SE)
  c10<-p10%>%select(Prediction, SE)
  c11<-p11%>%select(Prediction, SE)
  c12<-p12%>%select(Prediction, SE)
  
  
  format_numbers <- function(x, decimals) {
    if (is.numeric(x)) {
      sprintf(paste0("%.", decimals, "f"), x)
    } else {
      x
    }
  }
  
  
  
  rounding <- function(df) {
    df$Prediction <- sapply(df$Prediction, format_numbers, decimals = 3)
    df$SE <- sapply(df$SE, format_numbers, decimals = 3)
    df <- data.frame(lapply(df, factor))
    return(df)
  }
  
  c1to12<-list(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12)
  c1to12_rounded<-lapply(c1to12,rounding)
  
  study1.means<-tibble(
    Conditions = c("Control","Strong Con", "Weak Con", "Weak Pro","Strong Pro",rep("",5)),
    Entries = c(rep("Mean",5),rep("SE",5)),
    att.all.raw = unlist(c1to12_rounded[[1]], use.names = FALSE),
    att.all.adj = unlist(c1to12_rounded[[2]], use.names = FALSE),
    att.dem.raw = unlist(c1to12_rounded[[3]], use.names = FALSE),
    att.dem.adj = unlist(c1to12_rounded[[4]], use.names = FALSE),
    att.rep.raw = unlist(c1to12_rounded[[5]], use.names = FALSE),
    att.rep.adj = unlist(c1to12_rounded[[6]], use.names = FALSE),
    bel.all.raw = unlist(c1to12_rounded[[7]], use.names = FALSE),
    bel.all.adj = unlist(c1to12_rounded[[8]], use.names = FALSE),
    bel.dem.raw = unlist(c1to12_rounded[[9]], use.names = FALSE),
    bel.dem.adj = unlist(c1to12_rounded[[10]], use.names = FALSE),
    bel.rep.raw = unlist(c1to12_rounded[[11]], use.names = FALSE),
    bel.rep.adj = unlist(c1to12_rounded[[12]], use.names = FALSE),
    order = rep(1:5,2)
  )%>%
    arrange(order)%>%
    select(-order)
  
  
  print(xtable(study1.means), include.rownames = F)
  
  # Figure S7: Study 1 Results With and Without Covariates -----
  
  
  # https://andrewpwheeler.com/2016/10/19/testing-the-equality-of-two-regression-coefficients/
  
  
  aca<-aca%>%
    mutate(aca.c = aca - w1aca,
           cost.c = cost - w1cost)
  
  m2<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))
  m3<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))
  
  m5<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==1)))
  m6<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid,data=subset(aca,dem==0)))
  
  m2a<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid+factor(age3)+female+white+income+educ2+class+insurance,data=subset(aca,dem==1)))
  m3a<-tidy(lm_robust(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid+factor(age3)+female+white+income+educ2+class+insurance,data=subset(aca,dem==0)))
  
  m5a<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid+factor(age3)+female+white+income+educ2+class+insurance,data=subset(aca,dem==1)))
  m6a<-tidy(lm_robust(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid+factor(age3)+female+white+income+educ2+class+insurance,data=subset(aca,dem==0)))
  
  m2u<-tidy(lm_robust(aca~cond,data=subset(aca,dem==1)))
  m3u<-tidy(lm_robust(aca~cond,data=subset(aca,dem==0)))
  
  m5u<-tidy(lm_robust(cost~cond,data=subset(aca,dem==1)))
  m6u<-tidy(lm_robust(cost~cond,data=subset(aca,dem==0)))
  
  m2c<-tidy(lm_robust(aca.c~cond,data=subset(aca,dem==1)))
  m3c<-tidy(lm_robust(aca.c~cond,data=subset(aca,dem==0)))
  
  m5c<-tidy(lm_robust(cost.c~cond,data=subset(aca,dem==1)))
  m6c<-tidy(lm_robust(cost.c~cond,data=subset(aca,dem==0)))
  
  
  ##combining regression estimates into dataframes
  tcost<-bind_rows(dem=m5[2:5,],rep=m6[2:5,],.id="pid")
  tcost$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca<-bind_rows(dem=m2[2:5,],rep=m3[2:5,],.id="pid")
  taca$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  tcost.u<-bind_rows(dem=m5u[2:5,],rep=m6u[2:5,],.id="pid")
  tcost.u$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca.u<-bind_rows(dem=m2u[2:5,],rep=m3u[2:5,],.id="pid")
  taca.u$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  tcost.c<-bind_rows(dem=m5c[2:5,],rep=m6c[2:5,],.id="pid")
  tcost.c$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca.c<-bind_rows(dem=m2c[2:5,],rep=m3c[2:5,],.id="pid")
  taca.c$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  tcost.a<-bind_rows(dem=m5a[2:5,],rep=m6a[2:5,],.id="pid")
  tcost.a$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  taca.a<-bind_rows(dem=m2a[2:5,],rep=m3a[2:5,],.id="pid")
  taca.a$subject<-as.factor(c(2,2,2,2,3,3,3,3))
  
  
  ##partisan heterogeneity models
  het1<-tidy(lm_robust(aca~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca)))
  het2<-tidy(lm_robust(cost~cond*dem+w1aca*dem+w1cost*dem+pid*dem+w1obama*dem+w1obamahc*dem,data=subset(aca)))
  
  het1a<-tidy(lm_robust(aca~(cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid+factor(age3)+female+white+income+educ2+class+insurance)*dem,data=subset(aca)))
  het2a<-tidy(lm_robust(cost~(cond+w1aca+w1cost+pid+w1obama+w1obamahc+pid+factor(age3)+female+white+income+educ2+class+insurance)*dem,data=subset(aca)))
  
  het1u<-tidy(lm_robust(aca~cond*dem,data=subset(aca)))
  het2u<-tidy(lm_robust(cost~cond*dem,data=subset(aca)))
  
  het1c<-tidy(lm_robust(aca.c~cond*dem,data=subset(aca)))
  het2c<-tidy(lm_robust(cost.c~cond*dem,data=subset(aca)))
  
  ##storing heterogeneity estimates in dfs
  hcost<-het2[12:15,]
  haca<-het1[12:15,]
  hcost.u<-het2u[7:10,]
  haca.u<-het1u[7:10,]
  hcost.c<-het2c[7:10,]
  haca.c<-het1c[7:10,]
  
  hcost.a<-het2a[20:23,]
  haca.a<-het1a[20:23,]
  
  
  ##Common theme f
  th<-theme(panel.grid.major =element_blank(),
            panel.grid.minor=element_blank(),
            #  panel.grid.major.y = element_line(color = "grey80", linetype = "dashed", size = .2),
            panel.border=element_rect(colour="black"),
            axis.title.x=element_blank(),
            legend.position = c(0.1, 0.8),
            legend.background = element_blank(),
            legend.text=element_text(size=6),
            legend.key.size = unit(0.5, 'mm'),
            #   plot.title = element_text(size=7,hjust=0.5),
            plot.title = element_blank(),
            strip.text = element_text(size = 7),
            strip.background = element_rect(fill ="white",color = "white",size=1),
            axis.title.y= element_text(color = "black", size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=6))
  
  
  
  
  aca.df<-rbind(taca.u, taca, taca.a, taca.c)%>%
    mutate(model = c(rep("A1: No Covariate", 8),
                     rep("A2: Main Specification", 8),
                     rep("A3: Additional Covariates", 8),
                     rep("A4: No Covariate (DV = Change)", 8)
    ))
  
  
  ggplot(data=aca.df, aes(x=term, y=estimate, shape=pid,color=pid))+
    facet_grid(. ~ model)+
    geom_point(aes(),position=position_dodge(0.3),size=2,alpha=1)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Dem", "Rep"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Dem", "Rep"),
                       values=c("black","navy","red4"))+
    theme_bw()+
    scale_x_discrete(breaks=c("cond1","cond2","cond3","cond4"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.3), size=0.4)+
    labs(title="A: Treatment Effects on Attitude",x="", y = "A: Treatment Effects on Attitude")+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    ylim(-0.2,0.2)+
    th+theme(axis.ticks.y = element_line(colour = "black"))
  ggsave("figs7a.pdf",width=6.4,height=2)
  
  
  
  haca.df<-rbind(haca.u, haca, haca.a, haca.c)%>%
    mutate(model = c(rep("B1: No Covariate", 4),
                     rep("B2: Main Specification", 4),
                     rep("B3: Additional Covariates", 4),
                     rep("B4: No Covariate (DV = Change)", 4)
    ))
  
  
  ggplot(data=haca.df, aes(x=term, y=estimate))+ 
    facet_grid(. ~ model)+
    geom_point(aes(),size=2,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_discrete(breaks=c("cond1:dem","cond2:dem","cond3:dem","cond4:dem"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.4)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(B1) Different Effects on Attitude (Unadjusted) ",x="", y = "B: Party Diff in Effect on Attitude")+
    ylim(-0.2,0.2)+
    annotate(geom="text", x=1, y=0.18, 
             label="Pos Diff = Widening Partisan Gap", size=1.8, hjust=0) + 
    annotate(geom="text", x=1, y=-0.18, 
             label="Neg Diff = Narrowing Partisan Gap", size=1.8, hjust=0) +
    th
  ggsave("figs7b.pdf",width=6.4,height=2)
  
  
  
  
  cost.df<-rbind(tcost.u, tcost, tcost.a, tcost.c)%>%
    mutate(model = c(rep("C1: No Covariate", 8),
                     rep("C2: Main Specification", 8),
                     rep("C3: Additional Covariates", 8),
                     rep("C4: No Covariate (DV = Change)", 8)
    ))
  
  
  ggplot(data=cost.df, aes(x=term, y=estimate, shape=pid,color=pid))+
    facet_grid(. ~ model)+
    geom_point(aes(),position=position_dodge(0.3),size=2,alpha=1)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Dem", "Rep"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Dem", "Rep"),
                       values=c("black","navy","red4"))+
    theme_bw()+
    scale_x_discrete(breaks=c("cond1","cond2","cond3","cond4"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.3), size=0.4)+
    labs(title="C: Treatment Effects on Belief",x="", y = "c: Treatment Effects on Belief")+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    ylim(-0.21,0.2)+
    th+theme(axis.ticks.y = element_line(colour = "black"))
  ggsave("figs7c.pdf",width=6.4,height=2)
  
  
  hcost.df<-rbind(hcost.u, hcost, hcost.a, hcost.c)%>%
    mutate(model = c(rep("D1: No Covariate", 4),
                     rep("D2: Main Specification", 4),
                     rep("D3: Additional Covariates", 4),
                     rep("D4: No Covariate (DV = Change)", 4)
    ))
  
  
  
  ggplot(data=hcost.df, aes(x=term, y=estimate))+ 
    facet_grid(. ~ model)+
    geom_point(aes(),size=2,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_discrete(breaks=c("cond1:dem","cond2:dem","cond3:dem","cond4:dem"),
                     labels=c("Strong \n Con","Weak \n Con","Weak \n Pro","Strong \n Pro"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.4)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(B1) Different Effects on Attitude (Unadjusted) ",x="", y = "D: Party Diff in Effect on Belief")+
    ylim(-0.2,0.2)+
    annotate(geom="text", x=1, y=0.18, 
             label="Pos Diff = Widening Partisan Gap", size=1.8, hjust=0) + 
    annotate(geom="text", x=1, y=-0.18, 
             label="Neg Diff = Narrowing Partisan Gap", size=1.8, hjust=0) +
    th
  ggsave("figs8d.pdf",width=6.4,height=2)
  
  
  ## APPENDIX B ----
  
  # Table S18: Estimates of the Main Regressions and Robustness Checks (Study 2) ----
  
  
  m1<-lm(aca~(cond+aca0+pid)*dem*priming,aca18)
  m2<-lm(aca~(cond)*dem*priming,aca18)
  m3<-lm(aca~(cond+aca0+pid)*dem*priming,aca18%>%subset(wgt==1))
  m4<-lm(aca~(cond)*dem*priming,aca18%>%subset(wgt==1))
  m5<-lm(cost~(cond+aca0+pid)*dem*priming,aca18)
  m6<-lm(cost~(cond)*dem*priming,aca18)
  m7<-lm(cost~(cond+aca0+pid)*dem*priming,aca18%>%subset(wgt==1))
  m8<-lm(cost~(cond)*dem*priming,aca18%>%subset(wgt==1))
  
  
  
  stargazer(m1,m2,m3,m4,m5,m6,m7,m8, 
            se=starprep(m1,m2,m3,m4,m5,m6,m7,m8,se_type="HC2"),
            dep.var.labels = c("DV = Attitude toward the ACA","DV = Belief that ACA Saves Healthcare Costs"),
            covariate.labels = c("Civil Con", "Uncivil Con", "Civil Pro", "Uncivil Pro","Baseline Attitude", "PID (Cont.)",
                                 "Democrat", "Univalent", 
                                 "Civil Con $\\times$ Dem","Uncivil Con $\\times$ Dem","Civil Pro $\\times$ Dem", "Uncivil Pro $\\times$ Dem",
                                 "Baseline $\\times$ Dem", "PID $\\times$ Dem", 
                                 "Civil Con $\\times$ Univ","Uncivil Con $\\times$ Univ","Civil Pro $\\times$ Univ", "Uncivil Pro $\\times$ Univ",
                                 "Baseline $\\times$ Univ", "PID $\\times$ Univ", "Dem $\\times$ Univ",
                                 "Civil Con $\\times$ Dem $\\times$ Univ","Uncivil Con $\\times$ Dem $\\times$ Univ","Civil Pro $\\times$ Dem $\\times$ Univ", "Uncivil Pro $\\times$ Dem $\\times$ Univ",
                                 "Baseline $\\times$ Dem $\\times$ Univ", "PID $\\times$ Dem $\\times$ Univ"), 
            star.cutoffs = c(.05, .01, .005),
            add.lines = list(c("Reported in Main Text","\\checkmark","","","","\\checkmark","","",""),
                             c("Covariates","\\checkmark","","\\checkmark","","\\checkmark","","\\checkmark",""),
                             c("Shirkers Dropped","","","\\checkmark","\\checkmark","","","\\checkmark","\\checkmark")),
            #         no.space = TRUE,
            style = "ajps",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  # Table S19: Estimates of Figure 3A in Tabular Form ----
  
  m1<-lm_robust(aca~(cond+aca0+pid),data=subset(aca18, priming ==0 & dem==0))%>%tidy()
  m2<-lm_robust(aca~(cond+aca0+pid),data=subset(aca18, priming ==1 & dem==0))%>%tidy()
  m3<-lm_robust(aca~(cond+aca0+pid),data=subset(aca18, priming ==0 & dem==1))%>%tidy()
  m4<-lm_robust(aca~(cond+aca0+pid),data=subset(aca18, priming ==1 & dem==1))%>%tidy()
  m5<-lm_robust(cost~(cond+aca0+pid),data=subset(aca18, priming ==0 & dem==0))%>%tidy()
  m6<-lm_robust(cost~(cond+aca0+pid),data=subset(aca18, priming ==1 & dem==0))%>%tidy()
  m7<-lm_robust(cost~(cond+aca0+pid),data=subset(aca18, priming ==0 & dem==1))%>%tidy()
  m8<-lm_robust(cost~(cond+aca0+pid),data=subset(aca18, priming ==1 & dem==1))%>%tidy()
  
  
  col.names<-c("Outcome","Parameter","Definition","Context","Reference","Coef","SE","P")
  col1<-c("$\\beta_1$","$\\beta_2$",
          "$\\beta_1+\\gamma_1$","$\\beta_2+\\gamma_2$",
          "$\\beta_1+\\delta_1$","$\\beta_2+\\delta_2$",
          "$\\beta_1+\\gamma_1+\\delta_1+\\theta_1$",
          "$\\beta_2+\\gamma_2+\\delta_2+\\theta_2$",
          "$\\beta_3$","$\\beta_4$",
          "$\\beta_3+\\gamma_3$","$\\beta_4+\\gamma_4$",
          "$\\beta_3+\\delta_3$","$\\beta_4+\\delta_4$",
          "$\\beta_3+\\gamma_3+\\delta_3+\\theta_3$",
          "$\\beta_4+\\gamma_4+\\delta_4+\\theta_4$")%>%rep(2)
  col2<-rep("Con effect on Rep",4)%>%c(rep("Con effect on Dem",4))%>%
    c(rep("Pro effect on Rep",4))%>%c(rep("Pro effect on Dem",4))%>%rep(2)
  col3<-c("Civil Ambi", "Uncivil Ambi","Civil Uni", "Uncivil Uni")%>%rep(8)
  bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')}
  
  
  
  tab<-bind_cols(x=rep(NA,32),y=rep(NA,32),z=rep(NA,32),k=rep(NA,32),kk=rep(NA,32),
                 bind_rows(m1[2:3,c(2:3,5)],m2[2:3,c(2:3,5)],m3[2:3,c(2:3,5)],m4[2:3,c(2:3,5)],
                           m1[4:5,c(2:3,5)],m2[4:5,c(2:3,5)],m3[4:5,c(2:3,5)],m4[4:5,c(2:3,5)],
                           m5[2:3,c(2:3,5)],m6[2:3,c(2:3,5)],m7[2:3,c(2:3,5)],m8[2:3,c(2:3,5)],
                           m5[4:5,c(2:3,5)],m6[4:5,c(2:3,5)],m7[4:5,c(2:3,5)],m8[4:5,c(2:3,5)]))%>%tibble()
  names(tab)<-col.names
  tab[1]<-c(rep("Attitude",16),rep("Belief",16))
  tab[2]<-col1
  tab[3]<-col2
  tab[4]<-col3
  tab[5]<-c(paste0("Fig \\ref{s2-1}A-",1:4)%>%rep(2),paste0("Fig \\ref{s2-1}A-",5:8)%>%rep(2),
            paste0("Fig \\ref{s2-2}A-",1:4)%>%rep(2),paste0("Fig \\ref{s2-2}A-",5:8)%>%rep(2))
  print(xtable::xtable(tab,digits=c(0,0,0,0,0,0,2,2,4)),sanitize.text.function=function(x){x}, include.rownames=F,sanitize.colnames.function=bold)
  
  
  
  # Table S20: Estimates of Figures 3B and S4B in Tabular Form ----
  
  
  
  md<-lm_robust(aca~(cond+aca0+pid)*priming*rep,aca18) #marginal effects among dems
  mr<-lm_robust(aca~(cond+aca0+pid)*priming*dem,aca18) #marginal effects among reps
  
  attitude.diff<-bind_rows(
    mr%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond1:priming=0"))%>%tidy(), 
    mr%>%glht(linfct=c("cond2-cond1+cond2:priming=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond3:priming=0"))%>%tidy(), 
    mr%>%glht(linfct=c("cond4-cond3+cond4:priming=0"))%>%tidy(),
    md%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    md%>%glht(linfct=c("cond1:priming=0"))%>%tidy(), 
    md%>%glht(linfct=c("cond2-cond1+cond2:priming=0"))%>%tidy(),
    md%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    md%>%glht(linfct=c("cond3:priming=0"))%>%tidy(), 
    md%>%glht(linfct=c("cond4-cond3+cond4:priming=0"))%>%tidy()
  )
  
  md<-lm_robust(cost~(cond+aca0+pid)*priming*rep,aca18) #marginal effects among dems
  mr<-lm_robust(cost~(cond+aca0+pid)*priming*dem,aca18) #marginal effects among reps
  
  belief.diff<-bind_rows(
    mr%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond1:priming=0"))%>%tidy(), 
    mr%>%glht(linfct=c("cond2-cond1+cond2:priming=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond3:priming=0"))%>%tidy(), 
    mr%>%glht(linfct=c("cond4-cond3+cond4:priming=0"))%>%tidy(),
    md%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    md%>%glht(linfct=c("cond1:priming=0"))%>%tidy(), 
    md%>%glht(linfct=c("cond2-cond1+cond2:priming=0"))%>%tidy(),
    md%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    md%>%glht(linfct=c("cond3:priming=0"))%>%tidy(), 
    md%>%glht(linfct=c("cond4-cond3+cond4:priming=0"))%>%tidy()
  )
  
  diff<-bind_rows(attitude.diff,belief.diff)%>%dplyr::select(-statistic)
  
  col1<-c("$\\beta_2-\\beta_1$",
          "$\\gamma_1$",
          "$\\beta_2+\\gamma_2-\\beta_1$",
          "$\\beta_4-\\beta_3$",
          "$\\gamma_3$",
          "$\\beta_4+\\gamma_4-\\beta_3$",
          "$\\beta_2+\\delta_2-\\beta_1-\\delta_1$",
          "$\\gamma_1+\\theta_1$",
          "$\\beta_2+\\gamma_2+\\delta_2+\\theta_2-\\beta_1-\\delta_1$",
          "$\\beta_4+\\delta_4-\\beta_3-\\delta_3$",
          "$\\gamma_3+\\theta_3$",
          "$\\beta_4+\\gamma_4+\\delta_4+\\theta_4-\\beta_3-\\delta_3$")%>%rep(2)
  
  col2<-rep("Diff in Con Effect on Rep",3)%>%c(rep("Diff in Pro Effect on Rep",3))%>%
    c(rep("Diff in Con Effect on Dem",3))%>%c(rep("Diff in Pro Effect on Dem",3))%>%rep(2)
  
  col3<-c("Uncivil/Ambi vs. Base","Civil/Uni vs. Base","Uncivil/Uni vs. Base")%>%rep(8)
  
  tab<-bind_cols(x=rep(NA,24),y=rep(NA,24),z=rep(NA,24),k=rep(NA,24),kk=rep(NA,24),
                 diff[,3:5])%>%tibble()
  
  names(tab)<-col.names
  tab[1]<-c(rep("Attitude",12),rep("Belief",12))
  tab[2]<-col1
  tab[3]<-col2
  tab[4]<-col3
  tab[5]<-c(paste0("Fig \\ref{s2-1}B-",c(2,3,4,6,7,8))%>%rep(2),
            paste0("Fig \\ref{s2-2}B-",c(2,3,4,6,7,8))%>%rep(2))
  print(xtable::xtable(tab,digits=c(0,0,0,0,0,0,2,2,4)),sanitize.text.function=function(x){x}, include.rownames=F,sanitize.colnames.function=bold)
  
  
  
  # Table S21: Estimates of Figures 3C and S4C in Tabular Form ----
  
  
  
  
  het1<-tidy(lm_robust(cost~(cond+aca0+pid)*dem,data=subset(aca18,priming==0)))[9:12,]
  het2<-tidy(lm_robust(cost~(cond+aca0+pid)*dem,data=subset(aca18,priming==1)))[9:12,]
  het3<-tidy(lm_robust(aca~(cond+aca0+pid)*dem,data=subset(aca18,priming==0)))[9:12,]
  het4<-tidy(lm_robust(aca~(cond+aca0+pid)*dem,data=subset(aca18,priming==1)))[9:12,]
  belief.het<-bind_rows(het1,het2)
  attitude.het<-bind_rows(het3,het4)
  belief.het$x<-c(1,2,5,6,3,4,7,8)
  attitude.het$x<-c(1,2,5,6,3,4,7,8)
  
  
  attitude.het<-attitude.het[order(attitude.het$x),]
  belief.het<-belief.het[order(belief.het$x),]
  
  
  att.het.avg<-lm_robust(aca~(cond+aca0+pid)*priming*dem,aca18)%>%
    glht(linfct = "((cond2:dem+cond4:dem)*2+ 
         cond2:priming:dem+cond4:priming:dem+
         cond1:dem+cond3:dem+
         cond1:priming:dem+cond3:priming:dem )/6=0")%>%
    tidy()%>%rename(p.value = adj.p.value)
  
  
  bel.het.avg<-lm_robust(cost~(cond+aca0+pid)*priming*dem,aca18)%>%
    glht(linfct = "((cond2:dem+cond4:dem)*2+
         cond2:priming:dem+cond4:priming:dem+
         cond1:dem+cond3:dem+
         cond1:priming:dem+cond3:priming:dem )/6=0")%>%
    tidy()%>%rename(p.value = adj.p.value)
  
  
  
  col1<-c("$\\delta_1$",
          "$\\delta_2$",
          "$\\delta_1+\\theta_1$",
          "$\\delta_2+\\theta_2$",
          "$\\delta_3$",
          "$\\delta_4$",
          "$\\delta_3+\\theta_3$",
          "$\\delta_4+\\theta_4$",
          "$(\\delta_1+2\\delta_2+\\theta_1+\\theta_2+\\delta_3+2\\delta_4+\\theta_3+\\theta_4)/6$")%>%rep(2)
  
  
  col2<-rep("Partisan Diff in Con Effect",4)%>%c(rep("Partisan Diff in Pro Effect",4))%>%c("Average of 6 Partisan Diffs")%>%rep(2)
  col3<-c("Civil Ambi", "Uncivil Ambi","Civil Uni", "Uncivil Uni")%>%rep(2)%>%
    c("Contentious (Uncivil or Univalent)")%>%rep(2)
  
  
  tab<-bind_cols(x=rep(NA,18),y=rep(NA,18),z=rep(NA,18),k=rep(NA,18),kk=rep(NA,18),
                 bind_rows(
                   attitude.het[,c(2:3,5)],
                   att.het.avg[,c(3:4,6)],
                   belief.het[,c(2:3,5)],
                   bel.het.avg[,c(3:4,6)]),
  )%>%tibble()
  
  
  
  names(tab)<-col.names
  tab[1]<-c(rep("Attitude",9),rep("Belief",9))
  tab[2]<-col1
  tab[3]<-col2
  tab[4]<-col3
  tab[5]<-c(paste0("Fig \\ref{s2-1}C-",1:8),"P XX",
            paste0("Fig \\ref{s2-2}C-",1:8),"P XX")
  print(xtable::xtable(tab,digits=c(0,0,0,0,0,0,2,2,4)),sanitize.text.function=function(x){x}, 
        include.rownames=F,sanitize.colnames.function=bold)
  
  
  
  # Table S22: Estimates of Figures 3D and S4D in Tabular Form ----
  
  
  
  m<-lm_robust(aca~(cond+aca0+pid)*priming*dem,aca18)
  attitude.tri<-bind_rows(
    m%>%glht(linfct=c("cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond1:priming:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond2:priming:dem+cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:dem-cond3:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond3:priming:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:priming:dem+cond4:dem-cond3:dem=0"))%>%tidy(),
    m%>%
      glht(linfct = "(2*cond2:dem-2*cond1:dem+
   cond1:priming:dem+
   cond2:priming:dem+
   2*cond4:dem-2*cond3:dem+
   cond3:priming:dem+
   cond4:priming:dem)/6=0")%>%
      tidy()
  )
  
  
  m<-lm_robust(cost~(cond+aca0+pid)*priming*dem,aca18)
  belief.tri<-bind_rows(
    m%>%glht(linfct=c("cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond1:priming:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond2:priming:dem+cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:dem-cond3:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond3:priming:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:priming:dem+cond4:dem-cond3:dem=0"))%>%tidy(),
    m%>%
      glht(linfct = "(2*cond2:dem-2*cond1:dem+
   cond1:priming:dem+
   cond2:priming:dem+
   2*cond4:dem-2*cond3:dem+
   cond3:priming:dem+
   cond4:priming:dem)/6=0")%>%
      tidy()
  )
  
  
  col.names<-c("Outcome","Parameter","Definition","Context","Reference","Coef","SE","P")
  col1<-c("$\\delta_2-\\delta_1$",
          "$\\theta_1$",
          "$\\delta_2+\\theta_2-\\delta_1$",
          "$\\delta_4-\\delta_3$",
          "$\\delta_4+\\theta_4-\\delta_3$",
          "$\\theta_3$",
          "$(2\\delta_2-2\\delta_1+\\theta_1+\\theta_2+2\\delta_4-2\\delta_3+\\theta_3+\\theta_4)/6$")%>%rep(2)
  col2<-rep("Diff in Partisan Diff in Con Effect",3)%>%
    c(rep("Diff in Partisan Diff in Pro Effect",3))%>%
    c(rep("Average of Diffs in Partisan Diff",1))%>%rep(2)
  col3<-c("Uncivil/Ambi vs. Base", "Civil/Uni vs. Base","Uncivil/Uni vs. Base")%>%rep(2)%>%c("Contentious vs. Base")%>%rep(2)
  bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')}
  
  
  tab<-bind_cols(x=rep(NA,14),y=rep(NA,14),z=rep(NA,14),k=rep(NA,14),kk=rep(NA,14),
                 bind_rows(attitude.tri[,c(3,4,6)],belief.tri[,c(3,4,6)]))%>%tibble()
  names(tab)<-col.names
  tab[1]<-c(rep("Attitude",7),rep("Belief",7))
  tab[2]<-col1
  tab[3]<-col2
  tab[4]<-col3
  tab[5]<-paste0("Fig \\ref{s2-1}D-",c(2:4,6:8))%>%c("")%>%c(paste0("Fig \\ref{s2-2}D-",c(2:4,6:8)))%>%c("")
  print(xtable::xtable(tab,digits=c(0,0,0,0,0,0,2,2,4)),sanitize.text.function=function(x){x}, 
        include.rownames=F,sanitize.colnames.function=bold)
  
  
  
  
  
  # Table S23: Estimates of Figures 5 and S9 in Tabular Form ----
  
  
  uncon1<-md%>%glht(linfct="(cond3+cond3:rep-cond1)/2=0")%>%tidy() 
  uncon2<-md%>%glht(linfct="(cond4+cond4:rep-cond2)/2=0")%>%tidy() 
  uncon3<-md%>%glht(linfct="(cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming)/2=0")%>%tidy() 
  uncon4<-md%>%glht(linfct="(cond4+cond4:rep+cond4:priming+cond4:priming:rep-cond2-cond2:priming)/2=0")%>%tidy() 
  uncon5<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  uncon6<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3:priming+cond3:priming:rep-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming-2*cond3-2*cond3:rep+2*cond1)/6=0")%>%tidy() 
  belief.uncongenial<-bind_rows(uncon1,uncon2,uncon3,uncon4,uncon5,uncon6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  
  
  #### Congenial info effects across different contexts
  conge1<-mr%>%glht(linfct="(cond3+cond3:dem-cond1)/2=0")%>%tidy() 
  conge2<-mr%>%glht(linfct="(cond4+cond4:dem-cond2)/2=0")%>%tidy() 
  conge3<-mr%>%glht(linfct="(cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming)/2=0")%>%tidy() 
  conge4<-mr%>%glht(linfct="(cond4+cond4:dem+cond4:priming+cond4:priming:dem-cond2-cond2:priming)/2=0")%>%tidy() 
  conge5<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  conge6<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3:priming+cond3:priming:dem-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming-2*cond3-2*cond3:dem+2*cond1)/6=0")%>%tidy() 
  belief.congenial<-bind_rows(conge1,conge2,conge3,conge4,conge5,conge6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  
  belief.conuncon<-bind_rows(belief.congenial, belief.uncongenial)[c(1,5,6,7,11,12),]%>%
    bind_cols(info=c(rep("congenial",3),rep("uncongenial",3)), x = c(1,2,3,1,2,3))
  
  
  belief.conuncon$conf.low<-belief.conuncon$estimate-1.96*belief.conuncon$std.error
  belief.conuncon$conf.high<-belief.conuncon$estimate+1.96*belief.conuncon$std.error
  
  belief.conuncon$conf.low2<-belief.conuncon$estimate-1.645*belief.conuncon$std.error
  belief.conuncon$conf.high2<-belief.conuncon$estimate+1.645*belief.conuncon$std.error
  
  
  conuncon<-bind_rows(attitude.conuncon,belief.conuncon)
  
  
  col.names<-c("Outcome","Parameter","Definition","Reference","Coef","SE","P")
  col1<-c("$(-\\beta_1 + \\beta_3 + \\delta_3)/2$",
          "$(-\\beta_1-2\\beta_2+\\beta_3+2\\beta_4-\\gamma_1-\\gamma_2+\\gamma_3+\\gamma_4+\\delta_3+2\\delta_4+\\theta_3+\\theta_4)/6$",
          "$(2\\beta_1-2\\beta_2-2\\beta_3+2\\beta_4-\\gamma_1-\\gamma_2+\\gamma_3+\\gamma_4-2\\delta_3+2\\delta_4+\\theta_3+\\theta_4)/6$",
          "$(-\\beta_1 + \\beta_3 - \\delta_1)/2$",
          "$(-\\beta_1-2\\beta_2+\\beta_3+2\\beta_4-\\gamma_1-\\gamma_2+\\gamma_3+\\gamma_4-\\delta_1-2\\delta_2-\\theta_1-\\theta_2)/6$",
          "$(2\\beta_1-2\\beta_2-2\\beta_3+2\\beta_4-\\gamma_1-\\gamma_2+\\gamma_3+\\gamma_4+2\\delta_1-2\\delta_2-\\theta_1-\\theta_2)/6$")%>%
    rep(2)
  col2<-c("Average Magnitude of Congenial Info Effects (Baseline)",
          "Average Magnitude of Congenial Info Effects (Contentious)",
          "Difference in Magnitudes of Congenial Info Effects (Contentious vs. Base)",
          "Average Magnitude of Uncongenial Info Effects (Baseline)",
          "Average Magnitude of Uncongenial Info Effects (Contentious)",
          "Difference in Magnitudes of Uncongenial Info Effects (Contentious vs. Base)")%>%rep(2)
  bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')}
  
  
  tab<-bind_cols(x=rep(NA,12),y=rep(NA,12),z=rep(NA,12),k=rep(NA,12),
                 conuncon[,c(3,4,6)])%>%tibble()
  names(tab)<-col.names
  tab[1]<-c(rep("Attitude",6),rep("Belief",6))
  tab[2]<-col1
  tab[3]<-col2
  tab[4]<-c("Fig \\ref{s2-pool1}A","Fig \\ref{s2-pool1}A","Fig \\ref{s2-pool1}B",
            "Fig \\ref{s2-pool1}A","Fig \\ref{s2-pool1}A","Fig \\ref{s2-pool1}B",
            "Fig \\ref{s2-pool2}A","Fig \\ref{s2-pool2}A","Fig \\ref{s2-pool2}B",
            "Fig \\ref{s2-pool2}A","Fig \\ref{s2-pool2}A","Fig \\ref{s2-pool2}B")
  print(xtable::xtable(tab,digits=c(0,0,0,00,0,2,2,4)),sanitize.text.function=function(x){x}, 
        include.rownames=F,sanitize.colnames.function=bold)
  
  
  # Figure S8: Effects of New Information on Belief about the ACA in across Contexts ----
  
  m1<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,priming==0)))
  m2<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0)))
  m3<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0)))
  m7<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,priming==1)))
  m8<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1)))
  m9<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1)))
  
  ##hetero effect models
  het1<-tidy(lm_robust(cost~(cond+aca0+pid)*dem,data=subset(aca18,priming==0)))[9:12,]
  het2<-tidy(lm_robust(cost~(cond+aca0+pid)*dem,data=subset(aca18,priming==1)))[9:12,]
  
  ##3-way
  tri1<-tidy(lm_robust(cost~(cond+aca0+pid)*dem*priming,data=subset(aca18)))
  
  ###Storing estimates 
  belief<-bind_rows(aam=m1[2:5,],dam=m2[2:5,],ram=m3[2:5,],
                    aun=m7[2:5,],dun=m8[2:5,],run=m9[2:5,],.id="type")
  belief$pid<-rep(c(rep("all",4),rep("dem",4),rep("rep",4)),2)
  belief$x<-c(rep(c(1,2,5,6),3),rep(c(3,4,7,8),3))
  
  belief$conf.low2<-belief$estimate-1.645*belief$std.error
  belief$conf.high2<-belief$estimate+1.645*belief$std.error
  
  
  belief.het<-bind_rows(het1,het2)
  belief.het$x<-c(1,2,5,6,3,4,7,8)
  belief.het$conf.low2<-belief.het$estimate-1.645*belief.het$std.error
  belief.het$conf.high2<-belief.het$estimate+1.645*belief.het$std.error
  
  
  
  md<-lm_robust(cost~(cond+aca0+pid)*priming*rep,aca18) #marginal effects among dems
  mr<-lm_robust(cost~(cond+aca0+pid)*priming*dem,aca18) #marginal effects among reps
  m<-lm_robust(cost~(cond+aca0+pid)*priming*dem,aca18)
  
  belief.diff<-bind_rows(
    md%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    md%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    md%>%glht(linfct=c("cond1:priming=0"))%>%tidy(), 
    md%>%glht(linfct=c("cond2-cond1+cond2:priming=0"))%>%tidy(),
    md%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    md%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    md%>%glht(linfct=c("cond3:priming=0"))%>%tidy(), 
    md%>%glht(linfct=c("cond4-cond3+cond4:priming=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond2-cond1=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond1:priming=0"))%>%tidy(), 
    mr%>%glht(linfct=c("cond2-cond1+cond2:priming=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond4-cond3=0"))%>%tidy(),
    mr%>%glht(linfct=c("cond3:priming=0"))%>%tidy(), 
    mr%>%glht(linfct=c("cond4-cond3+cond4:priming=0"))%>%tidy()
  )
  belief.diff$x<-rep(1:8,2)
  belief.diff$pid<-c(rep("dem",8),rep("rep",8))
  belief.diff[c(1,5,9,13),2:6]<-NA
  
  
  belief.diff$conf.low2<-belief.diff$estimate-1.96*belief.diff$std.error
  belief.diff$conf.high2<-belief.diff$estimate+1.96*belief.diff$std.error
  
  belief.diff$conf.low<-belief.diff$estimate-1.645*belief.diff$std.error
  belief.diff$conf.high<-belief.diff$estimate+1.645*belief.diff$std.error
  
  
  belief.tri<-bind_rows(
    m%>%glht(linfct=c("cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond1:priming:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond2:priming:dem+cond2:dem-cond1:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:dem-cond3:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:dem-cond3:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond3:priming:dem=0"))%>%tidy(),
    m%>%glht(linfct=c("cond4:priming:dem+cond4:dem-cond3:dem=0"))%>%tidy()
  )
  belief.tri[1,2:6]<-NA
  belief.tri[5,2:6]<-NA
  belief.tri$x<-1:8
  
  belief.tri$conf.low<-belief.tri$estimate-1.96*belief.tri$std.error
  belief.tri$conf.high<-belief.tri$estimate+1.96*belief.tri$std.error
  
  belief.tri$conf.low2<-belief.tri$estimate-1.645*belief.tri$std.error
  belief.tri$conf.high2<-belief.tri$estimate+1.645*belief.tri$std.error
  
  
  
  th<-theme(panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            axis.title.x=element_blank(),
            legend.position = c(0.85, 0.25),
            legend.text=element_text(size=7),
            legend.key.size = unit(1.5, 'mm'),
            legend.background = element_rect(fill="transparent"),
            plot.title = element_text(size=9,hjust=0.5),
            axis.title.y= element_text(size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=7))
  
  xlab<- c("(1)\nCon\nCivil\nAmbi.","(2)\nCon\nUncivil\nAmbi.","(3)\nCon\nCivil\nUniv.","(4)\nCon\nUncivil\nUniv.",
           "(5)\nPro\nCivil\nAmbi.","(6)\nPro\nUncivil\nAmbi.","(7)\nPro\nCivil\nUniv.","(8)\nPro\nUncivil\nUniv.")
  
  
  
  
  ggplot(data=subset(belief,pid!="all"), aes(x=x, y=estimate,shape=pid,color=pid))+ 
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_point(aes(),position=position_dodge(0.5),size=3)+ 
    annotate(geom="text",x =c(1,3,5,7), y=c(0.18),
             label=c("Baseline", "Contentious Environments","Baseline", "Contentious Environments"),
             size=1.6,hjust=0.5)+
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c(16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c("navy","red4"))+
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    # geom_vline(xintercept = c(1.5,4.5,5.5), linetype="dotted",size=0.3,color="grey")+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.1)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.3, alpha=0.4)+
    labs(title="(A) Treatment Effect on Belief",x="", y = "Difference from Placebo")+
    ylim(-0.2,0.2)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    th
  ggsave("figs8a.png",width=3.25,height=2.5, dpi = 900)
  
  ggplot(data=subset(belief.diff), aes(x=x, y=estimate,shape=pid,color=pid))+ 
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_point(aes(),position=position_dodge(0.5),size=3)+ 
    annotate(geom="text",x =c(3,7,3,7,1,5), y=c(0.18,0.18,-0.18,-0.18,-0.02,-0.02),
             label=c("Positive =\nWeaker effect of con","Positive =\nStronger effect of pro",
                     "Negative =\nStronger effect of con","Negative =\nWeaker effect of pro",
                     "",""),
             size=1.6,hjust=0.5)+
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c(16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c("navy","red4"))+
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.1)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.3, alpha=0.4)+
    labs(title="(B)  Difference in Treatment Effects (vs. Baseline)",x="", y = "Diff-in-Diff (Contentious - Baseline)")+
    ylim(-0.2,0.2)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+th+
    theme(legend.position = "none")
  ggsave("figs8b.png",width=3.25,height=2.5, dpi = 900)
  
  
  
  ggplot(data=belief.het, aes(x=x, y=estimate))+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_point(aes(),size=3,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(C) Partisan Difference in Treatment Effects",x="", y = "Diff-in-Diff  (Dem - Rep)")+
    ylim(-0.2,0.2)+
    annotate(geom="text",x =4.5, y=c(-0.195,0.195),
             label=c("Negative = Treatment decreases partsan gap",
                     "Positive = Treatment increases partsan gap"),
             size=1.6,hjust=.5)+th
  ggsave("figs8c.png",width=3.25,height=2.5, dpi = 900)
  
  
  
  
  ggplot(data=belief.tri, aes(x=x, y=estimate))+ 
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_point(aes(),size=3,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.5), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(D) Difference in Partisan Differences (vs. Baseline)",x="", y = "Diff-in-Diff-in-Diff (Contentious - Baseline)")+
    ylim(-0.2,0.2)+
    annotate(geom="text",x =c(4.5,4.5,1,5), y=c(-0.195,0.195, -0.02, -0.02),
             label=c("Negative = Treatment decreases partsan gap more",
                     "Positive = Treatment increases partsan gap more",
                     "",""),
             size=1.6,hjust=.5)+
    th
  ggsave("figs8d.png",width=3.25,height=2.5, dpi = 900)
  
  
  # average divergence in belief under hostile
  
  m%>%
    glht(linfct = "((cond2:dem+cond4:dem)*2+
         cond2:priming:dem+cond4:priming:dem+
         cond1:dem+cond3:dem+
         cond1:priming:dem+cond3:priming:dem )/6=0")%>%
    tidy()
  
  # diff between average divergence in belief under hostile vs divergence under non-hostile
  
  m%>%glht(linfct=c("(2*cond2:dem-2*cond1:dem+
   cond1:priming:dem+
   cond2:priming:dem+
   2*cond4:dem-2*cond3:dem+
   cond3:priming:dem+
   cond4:priming:dem)/6=0"))%>%tidy()
  
  
  
  # Figure S9: Effects of New Information on Belief about the ACA (pooled) ----
  
  
  
  uncon1<-md%>%glht(linfct="(cond3+cond3:rep-cond1)/2=0")%>%tidy() 
  uncon2<-md%>%glht(linfct="(cond4+cond4:rep-cond2)/2=0")%>%tidy() 
  uncon3<-md%>%glht(linfct="(cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming)/2=0")%>%tidy() 
  uncon4<-md%>%glht(linfct="(cond4+cond4:rep+cond4:priming+cond4:priming:rep-cond2-cond2:priming)/2=0")%>%tidy() 
  uncon5<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  uncon6<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3:priming+cond3:priming:rep-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming-2*cond3-2*cond3:rep+2*cond1)/6=0")%>%tidy() 
  belief.uncongenial<-bind_rows(uncon1,uncon2,uncon3,uncon4,uncon5,uncon6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  
  
  #### Congenial info effects across different contexts
  conge1<-mr%>%glht(linfct="(cond3+cond3:dem-cond1)/2=0")%>%tidy() 
  conge2<-mr%>%glht(linfct="(cond4+cond4:dem-cond2)/2=0")%>%tidy() 
  conge3<-mr%>%glht(linfct="(cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming)/2=0")%>%tidy() 
  conge4<-mr%>%glht(linfct="(cond4+cond4:dem+cond4:priming+cond4:priming:dem-cond2-cond2:priming)/2=0")%>%tidy() 
  conge5<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  conge6<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3:priming+cond3:priming:dem-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming-2*cond3-2*cond3:dem+2*cond1)/6=0")%>%tidy() 
  belief.congenial<-bind_rows(conge1,conge2,conge3,conge4,conge5,conge6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  
  belief.conuncon<-bind_rows(belief.congenial, belief.uncongenial)[c(1,5,6,7,11,12),]%>%
    bind_cols(info=c(rep("congenial",3),rep("uncongenial",3)), x = c(1,2,3,1,2,3))
  
  
  belief.conuncon$conf.low<-belief.conuncon$estimate-1.96*belief.conuncon$std.error
  belief.conuncon$conf.high<-belief.conuncon$estimate+1.96*belief.conuncon$std.error
  
  belief.conuncon$conf.low2<-belief.conuncon$estimate-1.645*belief.conuncon$std.error
  belief.conuncon$conf.high2<-belief.conuncon$estimate+1.645*belief.conuncon$std.error
  
  
  ggplot(data=belief.conuncon[c(-3,-6),], aes(x=x, y=estimate, color=info))+ 
    geom_point(aes(),size=3,stroke =.4,position=position_dodge(0.1))+ 
    geom_line(position=position_dodge(0.1), size = 0.4, alpha = 0.7, linetype = "dashed")+
    theme_bw()+
    scale_color_manual(name = c(""),
                       breaks=c("congenial","uncongenial"),
                       labels = c("Congenial", "Uncongenial"),
                       values=c("black","#E7A500"))+
    scale_x_continuous(breaks = 1:2, limits = c(.5,2.5),
                       labels=c("Baseline\n(Civil and Ambivalent)","Contentious\n(Uncivil, Univalent, or both)"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.1), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.1), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(A) Effects of (Un)congenial Information (Pooled)",x="", y = "Pooled Effects on Belief (toward Information)")+
    annotate(geom="text",x =1.5, y=c(0.095,0.075),
             label=c("+0.01","-0.04"),
             color=c("black","#E7A500"),size=1.6,hjust=.5)+
    th+  theme(legend.position = c(0.18, 0.2))
  ggsave("figs9a.png",width=3.25,height=2.5, dpi = 900)
  
  
  ggplot(data=belief.conuncon[c(3,6),], aes(x=x, y=estimate, color=info))+ 
    geom_point(aes(),size=3,stroke =.4,position=position_dodge(0.1))+ 
    theme_bw()+
    scale_color_manual(name = c(""),
                       breaks=c("congenial","uncongenial"),
                       labels = c("Congenial", "Uncongenial"),
                       values=c("black","#E7A500"))+
    scale_x_continuous(breaks = 3, limits = c(2.5,3.5),
                       labels=c("Contentious vs. Baseline\n"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high), size=0.2,position=position_dodge(0.1))+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2), size=0.6, alpha=0.6,position=position_dodge(0.1))+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(B) Difference in Effects (Pooled)",x="", y = "Difference in Effects (Contentious - Baseline)")+
    th+  theme(legend.position = c(0.25, 0.2))
  ggsave("figs9b.png",width=3.25,height=2.5, dpi = 900)
  
  
  
  # Table S24: (Absence of) Main Effects of the PID Priming on ACA Opinions (Study 2) ----
  
  m1<-lm(aca~(priming+aca0+pid)*dem,aca18%>%subset(cond==0))
  m2<-lm(cost~(priming+aca0+pid)*dem,aca18%>%subset(cond==0))
  m3<-lm(aca~(priming+aca0+pid),aca18%>%subset(cond==0))
  m4<-lm(cost~(priming+aca0+pid),aca18%>%subset(cond==0))
  
  stargazer(m1,m2,m3,m4,
            se=starprep(m1,m2,m3,m4,se_type="HC2"),
            dep.var.labels = c("Attitude","Belief","Attitude","Belief"),
            order = c(1,4,5),
            covariate.labels = c("Univalent PID Prime (vs. Ambivalent Prime)", "Democrat","Univalent $\\times$ Democrat", 
                                 "Baseline Attitude", "PID (Continuous)", 
                                 "Baseline Attitude $\\times$ Democrat", "PID $\\times$ Democrat"),
            star.cutoffs = c(.05, .01, .005),
            style = "ajps",
            add.lines = list(
              c("Covariates","\\checkmark","\\checkmark","\\checkmark","\\checkmark")),
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  
  # Table S25: Manipulation Check on Partisanship Priming ----
  
  m1<-lm (inparty~priming,aca18)
  m2<-lm (inparty~priming*dem,aca18)
  m3<-lm (outparty~priming,aca18)
  m4<-lm (outparty~priming*dem,aca18)
  m5<-lm (ap~priming,aca18)
  m6<-lm (ap~priming*dem,aca18)
  
  stargazer(m1,m2,m3,m4,m5,m6,
            se=starprep(m1,m2,m3,m4,m5,m6,se_type="HC2"),
            dep.var.labels = c("In-Party","Out-Party","Affective Polarization"),
            #order = c(1,4,5),
            covariate.labels = c("Univalent PID Prime (vs. Ambivalent Prime)", "Democrat","Univalent $\\times$ Democrat"),
            star.cutoffs = c(.05, .01, .005),
            style = "ajps",
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  
  
  # Table S26: Manipulation Check on Message Civility ----
  
  aca18$condpool <- case_when(aca18$cond==1|aca18$cond==3~0,
                              aca18$cond==2|aca18$cond==4~1)
  
  m1<-lm(civil~condpool,aca18)
  m2<-lm(civil~condpool*dem,aca18)
  m3<-lm(civil~cond,aca18%>%subset(cond!="0"))
  m4<-lm(civil~cond*dem,aca18%>%subset(cond!="0"))
  
  stargazer(m1,m2,m3,m4, 
            se=starprep(m1,m2,m3,m4,se_type="HC2"),
            dep.var.labels = c("DV = Perceived Message Civility"),
            order = c(1,2,3,7,8,9,4,5,6),
            covariate.labels = c("Uncivil Conditions (Pooled)","Democrat","Uncivil $\\times$ Dem",
                                 "Con Uncivil", "Pro Civil", "Pro Uncivil",
                                 "Con Uncivil $\\times$ Dem", "Pro Civil $\\times$ Dem", "Pro Uncivil $\\times$ Dem"),
            star.cutoffs = c(.05, .01, .005),
            style = "ajps",
            add.lines = list(
              c("Conditions","Pooled","Pooled","Separate","Separate")),
            digits= 2,keep.stat = c("n","adj.rsq"))
  
  
  
  
  # Figure S10: Manipulation Check on Message Civility by Partisanship ----
  
  
  
  civil<-bind_rows(
    (lm_robust(civil~1,aca18%>%subset(cond=="1" & rep ==1))%>%tidy())[1,],
    (lm_robust(civil~1,aca18%>%subset(cond=="2" & rep ==1))%>%tidy())[1,],
    (lm_robust(civil~1,aca18%>%subset(cond=="3" & rep ==1))%>%tidy())[1,],
    (lm_robust(civil~1,aca18%>%subset(cond=="4" & rep ==1))%>%tidy())[1,],
    (lm_robust(civil~1,aca18%>%subset(cond=="1" & dem ==1))%>%tidy())[1,],
    (lm_robust(civil~1,aca18%>%subset(cond=="2" & dem ==1))%>%tidy())[1,],
    (lm_robust(civil~1,aca18%>%subset(cond=="3" & dem ==1))%>%tidy())[1,],
    (lm_robust(civil~1,aca18%>%subset(cond=="4" & dem ==1))%>%tidy())[1,]
  )
  
  
  
  
  civil$pid<-c(rep("rep",4),rep("dem",4))
  civil$term<-rep(c("cond1","cond2","cond3","cond4"),2)
  civil$conf.low2<-civil$estimate-1.645*civil$std.error
  civil$conf.high2<-civil$estimate+1.645*civil$std.error
  
  
  th<-theme(panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            axis.title.x=element_blank(),
            legend.position = c(0.85, 0.25),
            legend.text=element_text(size=7),
            legend.key.size = unit(1.5, 'mm'),
            legend.background = element_rect(fill="transparent"),
            plot.title = element_text(size=9,hjust=0.5),
            axis.title.y= element_text(size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=7))
  
  
  ggplot(data=subset(civil,pid!="all"), aes(x=term, y=estimate,shape=pid,color=pid))+ 
    geom_point(aes(),size=3,alpha=1,position=position_dodge(0.5))+ 
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Democrat", "Republican"),
                       values=c(16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Democrat", "Republican"),
                       values=c("navy","red4"))+
    theme_bw()+
    scale_x_discrete(breaks=c("cond1","cond2","cond3","cond4"),
                     labels=c("Con\nCivil","Con\nUncivil","Pro\nCivil","Pro\nUncivil"))+
    theme(text=element_text(size=9))+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high), size=0.2,position=position_dodge(0.5))+
    geom_hline(yintercept = .5, linetype="dashed",size=0.2)+
    labs(title="Perceived Message Civility",x="", y = "Marginal Means")+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    th+theme(legend.position = c(0.15, 0.15))
  ggsave("figs10.png",width=3.25,height=4.5, dpi = 900)
  
  
  
  # Table S27: 2018 sample characteristics ---------
  
  vals <- tibble(
    variables = c("Total N", "Age","","","Gender","","Race","","Education","",
                  "Income","",
                  "PID","","","","","","",
                  "PID (Binary)","",
                  "PID Strength","",
                  "ACA Support", ""),
    values = c(
      "", "25 or younger", "26 to 34", "55 or older",
      "Men", "Women","None White", "White", "No BA Degree", "BA Degree",
      "Below 50K", "Above 50k", 
      "Strong Rep", "Moderate Rep", "Leaning Rep", "Pure Independent", "Leaning Dem", "Moderate Dem", "Strong Dem",
      "Republican (Combined)", "Democrat (Combined)",
      "Independent/Moderate","Strong Partisan",
      "No", "Yes"
    ))
  
  anes18.desc<-
    tibble(raw.prc = anes18%>%nrow())%>%
    rbind(anes18%>%filter(!is.na(age3))%>%frq(age3, weights = weight_spss, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes18%>%filter(!is.na(female))%>%frq(female, weights = weight_spss, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes18%>%filter(!is.na(white))%>%frq(white, weights = weight_spss, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes18%>%filter(!is.na(educ2))%>%frq(educ2, weights = weight_spss, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes18%>%filter(!is.na(income))%>%frq(income, weights = weight_spss, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes18%>%filter(!is.na(pid7))%>%frq(pid7, weights = weight_spss, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes18%>%frq(pid3, weights = weight_spss, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc)%>%slice(-2))%>%
    rbind(anes18%>%filter(!is.na(str))%>%frq(str, weights = weight_spss, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(anes18%>%filter(!is.na(support))%>%frq(support, weights = weight_spss, show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rename(anes18 = raw.prc)
  
  
  aca18.desc<-tibble(raw.prc = aca18%>%filter(!is.na(cond))%>%nrow())%>%
    rbind(aca18%>%filter(!is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca18%>%filter(!is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca18%>%filter(!is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca18%>%filter(!is.na(educ))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca18%>%filter(!is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca18%>%filter(!is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca18%>%filter(!is.na(pid7))%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca18%>%filter(!is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rbind(aca18%>%filter(!is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
    rename(aca18.all = raw.prc)%>%
    cbind(
      tibble(raw.prc = aca18%>%filter(cond=="1")%>%nrow())%>%
        rbind(aca18%>%filter(cond=="1" & !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="1"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="1"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="1"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="1"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="1"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="1"& !is.na(pid7) )%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="1"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="1"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca18.1 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca18%>%filter(cond=="2")%>%nrow())%>%
        rbind(aca18%>%filter(cond=="2"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="2"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="2"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="2"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="2"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="2"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="2" & !is.na(pid7))%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="2"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="2"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca18.2 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca18%>%filter(cond=="3")%>%nrow())%>%
        rbind(aca18%>%filter(cond=="3"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="3"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="3"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="3"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="3"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="3"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="3" & !is.na(pid7))%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="3"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="3"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca18.3 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca18%>%filter(cond=="4")%>%nrow())%>%
        rbind(aca18%>%filter(cond=="4"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="4"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="4"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="4"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="4"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="4"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="4" & !is.na(pid7))%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="4"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="4"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca18.4 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca18%>%filter(cond=="0")%>%nrow())%>%
        rbind(aca18%>%filter(cond=="0"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="0"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="0"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="0"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="0"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="0"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="0"& !is.na(pid7) )%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="0"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(cond=="0"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca18.5 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca18%>%filter(priming=="1")%>%nrow())%>%
        rbind(aca18%>%filter(priming=="1"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="1"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="1"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="1"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="1"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="1"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="1" & !is.na(pid7))%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="1"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="1"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca18.6 = raw.prc)
    )%>%
    cbind(
      tibble(raw.prc = aca18%>%filter(priming=="0")%>%nrow())%>%
        rbind(aca18%>%filter(priming=="0"& !is.na(age3))%>%frq(age3,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="0"& !is.na(female))%>%frq(female,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="0"& !is.na(white))%>%frq(white,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="0"& !is.na(educ2))%>%frq(educ2,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="0"& !is.na(income))%>%frq(income,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="0"& !is.na(pid7))%>%frq(pid7,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="0"& !is.na(pid7) )%>%frq(dem,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="0"& !is.na(str))%>%frq(str,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rbind(aca18%>%filter(priming=="0"& !is.na(support))%>%frq(support,  show.na =F)%>%data.frame()%>%tibble()%>%select(raw.prc))%>%
        rename(aca18.7 = raw.prc)
    )
  
  
  study2.desc<-cbind(vals, anes18.desc, aca18.desc)
  
  table.study2.desc<-study2.desc
  
  table.study2.desc%>%data.frame%>%xtable(digits = 0, align = "rllccccccccc")%>%print(include.rownames = FALSE)
  
  
  # Table S28: Heterogeneous Effects on Attitude under Ambivalent ----
  
  aca18$mod<-case_when(
    aca18$age3 == 0 ~ 1,
    aca18$age3 == 1 ~ 0
  )
  
  
  a <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  b <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  aca18$mod<-case_when(
    aca18$age3 == 2 ~ 1,
    aca18$age3 == 1 ~ 0)
  
  c <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  d <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  
  aca18$mod<-aca18$female
  
  e <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  f <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  aca18$mod<-aca18$white
  
  g <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  h <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  aca18$mod<-aca18$educ2
  
  i <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  j <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  aca18$mod<-aca18$income
  
  k <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  l <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  
  aca18$mod<-aca18$str
  
  m <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  n <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  
  aca18$mod<-aca18$support
  
  o <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  p <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  
  
  amb_att <- list(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
  
  holm<-0.05/144
  
  stargazer(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p, 
            se=starprep(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,se_type="HC2"),
            order = c(1,2,3,4,7,8,9,10,11,5,6,12,13),
            dep.var.labels.include = FALSE,
            covariate.labels = c("Civil Con (Mod = 0)", "Uncivil Con (Mod = 0)", "Civil Pro (Mod = 0)", "Uncivil Pro (Mod = 0)",
                                 "Moderator","Civil Con $\\times$ Mod","Uncivil Con $\\times$ Mod","Civil Pro $\\times$ Mod", "Uncivil Pro $\\times$ Mod"
                                 # ,
                                 # "W1 Attitude", "W1 Belief", "W1 PID Cont.", "W1 Obama", "W1 Obama HC",
                                 # "W1 Attitude $\\times$ Mod", "W1 Belief $\\times$ Mod", "W1 PID $\\times$ Mod", "W1 Obama $\\times$ Mod", "W1 Obama HC $\\times$ Mod"
            ),
            star.cutoffs = c(.05, holm),
            add.lines = list(c("Sample",rep(c("Rep","Dem"),9)),
                             #c("Priming",rep(c("Amb","Uni"),8)),
                             c("Moderator","Age","Age","Age","Age","Women","Women","White","White","B.A.", "B.A.", "High","High",
                               "Str","Str", "ACA","ACA", "Trump","Trump"),
                             c("","25-","25-","45+","45+","","","","","","","Income","Income","PID","PID", "Supp","Supp",  "Supp","Supp")                          
            ),
            no.space = TRUE,
            model.names = FALSE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2,
            digits.extra = 0,
            keep.stat = c("n"))
  
  
  
  
  # Table S29: Heterogeneous Effects on Attitude under Univalent ----
  
  aca18$mod<-case_when(
    aca18$age3 == 0 ~ 1,
    aca18$age3 == 1 ~ 0
  )
  
  
  a <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  b <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  aca18$mod<-case_when(
    aca18$age3 == 2 ~ 1,
    aca18$age3 == 1 ~ 0)
  
  c <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  d <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  
  aca18$mod<-aca18$female
  
  e <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  f <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  aca18$mod<-aca18$white
  
  g <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  h <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  aca18$mod<-aca18$educ2
  
  i <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  j <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  aca18$mod<-aca18$income
  
  k <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  l <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  
  aca18$mod<-aca18$str
  
  m <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  n <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  
  aca18$mod<-aca18$support
  
  o <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  p <-lm(aca~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  
  
  holm<-0.05/144
  
  uni_att <- list(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
  
  
  stargazer(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,
            se=starprep(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,se_type="HC2"),
            order = c(1,2,3,4,7,8,9,10,11,5,6,12,13),
            dep.var.labels.include = FALSE,
            covariate.labels = c("Civil Con (Mod = 0)", "Uncivil Con (Mod = 0)", "Civil Pro (Mod = 0)", "Uncivil Pro (Mod = 0)",
                                 "Moderator","Civil Con $\\times$ Mod","Uncivil Con $\\times$ Mod","Civil Pro $\\times$ Mod", "Uncivil Pro $\\times$ Mod"
                                 # ,
                                 # "W1 Attitude", "W1 Belief", "W1 PID Cont.", "W1 Obama", "W1 Obama HC",
                                 # "W1 Attitude $\\times$ Mod", "W1 Belief $\\times$ Mod", "W1 PID $\\times$ Mod", "W1 Obama $\\times$ Mod", "W1 Obama HC $\\times$ Mod"
            ),
            star.cutoffs = c(.05, holm),
            add.lines = list(c("Sample",rep(c("Rep","Dem"),9)),
                             #c("Priming",rep(c("Amb","Uni"),8)),
                             c("Moderator","Age","Age","Age","Age","Women","Women","White","White","B.A.", "B.A.", "High","High",
                               "Str","Str", "ACA","ACA", "Trump","Trump"),
                             c("","25-","25-","45+","45+","","","","","","","Income","Income","PID","PID", "Supp","Supp",  "Supp","Supp")                          
            ),
            no.space = TRUE,
            model.names = FALSE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2,
            digits.extra = 0,
            keep.stat = c("n"))
  
  
  
  
  
  
  # Table S30: Heterogeneous Effects on Belief under Univalent ----
  
  
  aca18$mod<-case_when(
    aca18$age3 == 0 ~ 1,
    aca18$age3 == 1 ~ 0
  )
  
  
  a <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  b <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  aca18$mod<-case_when(
    aca18$age3 == 2 ~ 1,
    aca18$age3 == 1 ~ 0)
  
  c <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  d <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  
  aca18$mod<-aca18$female
  
  e <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  f <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  aca18$mod<-aca18$white
  
  g <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  h <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  aca18$mod<-aca18$educ2
  
  i <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  j <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  aca18$mod<-aca18$income
  
  k <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  l <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  
  aca18$mod<-aca18$str
  
  m <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  n <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  
  aca18$mod<-aca18$support
  
  o <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==0))
  p <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==0 & dem==1))
  
  
  amb_bel <- list(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
  
  holm<-0.05/144
  
  stargazer(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,
            se=starprep(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,se_type="HC2"),
            order = c(1,2,3,4,7,8,9,10,11,5,6,12,13),
            dep.var.labels.include = FALSE,
            covariate.labels = c("Civil Con (Mod = 0)", "Uncivil Con (Mod = 0)", "Civil Pro (Mod = 0)", "Uncivil Pro (Mod = 0)",
                                 "Moderator","Civil Con $\\times$ Mod","Uncivil Con $\\times$ Mod","Civil Pro $\\times$ Mod", "Uncivil Pro $\\times$ Mod"
                                 # ,
                                 # "W1 Attitude", "W1 Belief", "W1 PID Cont.", "W1 Obama", "W1 Obama HC",
                                 # "W1 Attitude $\\times$ Mod", "W1 Belief $\\times$ Mod", "W1 PID $\\times$ Mod", "W1 Obama $\\times$ Mod", "W1 Obama HC $\\times$ Mod"
            ),
            star.cutoffs = c(.05, 0.0003472222),
            add.lines = list(c("Sample",rep(c("Rep","Dem"),9)),
                             #c("Priming",rep(c("Amb","Uni"),8)),
                             c("Moderator","Age","Age","Age","Age","Women","Women","White","White","B.A.", "B.A.", "High","High",
                               "Str","Str", "ACA","ACA", "Trump","Trump"),
                             c("","25-","25-","45+","45+","","","","","","","Income","Income","PID","PID", "Supp","Supp",  "Supp","Supp")                          
            ),
            no.space = TRUE,
            model.names = FALSE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2,
            digits.extra = 0,
            keep.stat = c("n"))
  
  
  
  # Table S31: Heterogeneous Effects on Belief under Univalent ----
  
  aca18$mod<-case_when(
    aca18$age3 == 0 ~ 1,
    aca18$age3 == 1 ~ 0
  )
  
  
  a <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  b <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  aca18$mod<-case_when(
    aca18$age3 == 2 ~ 1,
    aca18$age3 == 1 ~ 0)
  
  c <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  d <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  
  aca18$mod<-aca18$female
  
  e <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  f <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  aca18$mod<-aca18$white
  
  g <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  h <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  aca18$mod<-aca18$educ2
  
  i <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  j <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  aca18$mod<-aca18$income
  
  k <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  l <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  
  aca18$mod<-aca18$str
  
  m <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  n <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  
  aca18$mod<-aca18$support
  
  o <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==0))
  p <-lm(cost~(cond+aca0+pid)*mod,data=subset(aca18, priming ==1 & dem==1))
  
  
  uni_bel <- list(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
  
  holm<-0.05/144
  
  
  stargazer(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p, 
            se=starprep(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,se_type="HC2"),
            order = c(1,2,3,4,7,8,9,10,11,5,6,12,13),
            dep.var.labels.include = FALSE,
            covariate.labels = c("Civil Con (Mod = 0)", "Uncivil Con (Mod = 0)", "Civil Pro (Mod = 0)", "Uncivil Pro (Mod = 0)",
                                 "Moderator","Civil Con $\\times$ Mod","Uncivil Con $\\times$ Mod","Civil Pro $\\times$ Mod", "Uncivil Pro $\\times$ Mod"
                                 # ,
                                 # "W1 Attitude", "W1 Belief", "W1 PID Cont.", "W1 Obama", "W1 Obama HC",
                                 # "W1 Attitude $\\times$ Mod", "W1 Belief $\\times$ Mod", "W1 PID $\\times$ Mod", "W1 Obama $\\times$ Mod", "W1 Obama HC $\\times$ Mod"
            ),
            star.cutoffs = c(.05, holm),
            add.lines = list(c("Sample",rep(c("Rep","Dem"),9)),
                             #c("Priming",rep(c("Amb","Uni"),8)),
                             c("Moderator","Age","Age","Age","Age","Women","Women","White","White","B.A.", "B.A.", "High","High",
                               "Str","Str", "ACA","ACA", "Trump","Trump"),
                             c("","25-","25-","45+","45+","","","","","","","Income","Income","PID","PID", "Supp","Supp",  "Supp","Supp")                          
            ),
            no.space = TRUE,
            model.names = FALSE,
            column.sep.width = "5pt",
            style = "apsr",
            digits= 2,
            digits.extra = 0,
            keep.stat = c("n"))
  
  
  ps1<-bind_rows(lapply(amb_att, tidy),lapply(uni_att, tidy))%>%
    filter(term == "cond1:mod"|term == "cond2:mod"|term == "cond3:mod"|term == "cond4:mod")%>%
    pull(p.value)
  
  
  # Counting sig p-valus
  
  sum(ps1<.05)
  sum(ps1<.05)/length(ps1)
  sum(p.adjust(ps1, method = "holm")<.05)
  c(1:144)[p.adjust(ps1, method = "holm")<.05]
  
  
  ps2<-bind_rows(lapply(amb_bel, tidy),lapply(uni_bel, tidy))%>%
    filter(term == "cond1:mod"|term == "cond2:mod"|term == "cond3:mod"|term == "cond4:mod")%>%
    pull(p.value)
  sum(ps2<.05)
  sum(ps2<.05)/length(ps2)
  sum(p.adjust(ps2, method = "holm")<.05)
  
  p.adjust(ps2, method = "holm")<.05
  
  c(1:144)[p.adjust(ps2, method = "holm")<.05]
  
  
  # Figures S11 and S12: Study 2 Treatment Effects Weighted by Individual Factors ----
  
  # calculating weights
  aca18<-aca18%>%
    mutate(
      w1 = case_when(
        age3 == 0 ~ study2.desc$anes[2]/study2.desc$aca18.all[2],
        age3 == 1 ~ study2.desc$anes[3]/study2.desc$aca18.all[3],
        age3 == 2 ~ study2.desc$anes[4]/study2.desc$aca18.all[4]
      ),
      w2 = case_when(
        female == 0 ~ study2.desc$anes[5]/study2.desc$aca18.all[5],
        female == 1 ~ study2.desc$anes[6]/study2.desc$aca18.all[6]
      ),
      w3 = case_when(
        white == 0 ~ study2.desc$anes[7]/study2.desc$aca18.all[7],
        white == 1 ~ study2.desc$anes[8]/study2.desc$aca18.all[8]
      ),
      w4 = case_when(
        educ2 == 0 ~ study2.desc$anes[9]/study2.desc$aca18.all[9],
        educ2 == 1 ~ study2.desc$anes[10]/study2.desc$aca18.all[10]
      ),
      w5 = case_when(
        income == 0 ~ study2.desc$anes[11]/study2.desc$aca18.all[11],
        income == 1 ~ study2.desc$anes[12]/study2.desc$aca18.all[12]
      ),
      w6 = case_when(
        pid7 == 0 ~ study2.desc$anes[13]/study2.desc$aca18.all[13],
        pid7 == 1 ~ study2.desc$anes[14]/study2.desc$aca18.all[14],
        pid7 == 2 ~ study2.desc$anes[15]/study2.desc$aca18.all[15],
        pid7 == 3 ~ study2.desc$anes[16]/study2.desc$aca18.all[16],
        pid7 == 4 ~ study2.desc$anes[17]/study2.desc$aca18.all[17],
        pid7 == 5 ~ study2.desc$anes[18]/study2.desc$aca18.all[18],
        pid7 == 6 ~ study2.desc$anes[19]/study2.desc$aca18.all[19]
      ),
      w7 = case_when(
        support == 0 ~ study2.desc$anes[24]/study2.desc$aca18.all[24],
        support == 1 ~ study2.desc$anes[25]/study2.desc$aca18.all[25]
      )
    )
  
  
  # Figures
  
  th<-theme_bw()+ theme(panel.grid.major=element_blank(),
                        panel.grid.minor=element_blank(),
                        panel.border=element_rect(colour="black"),
                        axis.title.x=element_blank(),
                        legend.position = c(0.85, 0.25),
                        legend.text=element_text(size=6),
                        legend.key.size = unit(1.5, 'mm'),
                        legend.background = element_rect(fill="transparent"),
                        plot.title = element_text(size=6,hjust=0.5),
                        axis.title.y= element_text(size=6),
                        axis.text.x = element_text(color = "black", size=5),
                        axis.text.y = element_text(color = "black", size=6))
  
  xlab<- c("Con\nCivil\nAmbi","Con\nUncivil\nAmbi","Con\nCivil\nUniv","Con\nUncivil\nUniv",
           "Pro\nCivil\nAmbi","Pro\nUncivil\nAmbi","Pro\nCivil\nUniv","Pro\nUncivil\nUniv")
  
  
  plot<- function(data, title, file_name) {
    p<-ggplot(data=data, aes(x=x, y=estimate,shape=pid,color=pid))+ 
      geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
      geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
      geom_point(aes(),position=position_dodge(0.5),size=2)+ 
      annotate(geom="text",x =c(1,3,5,7), y=c(0.18),
               label=c("Baseline", "Contentious","Baseline", "Contentious"),
               size=1.6,hjust=0.5)+
      scale_shape_manual(name = c(""),
                         breaks=c("dem","rep"),
                         labels = c("Dem", "Rep"),
                         values=c(16, 17))+
      scale_color_manual(name = c(""),
                         breaks=c("dem","rep"),
                         labels = c("Dem", "Rep"),
                         values=c("navy","red4"))+
      theme_bw()+
      scale_x_continuous(breaks = 1:8,
                         labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
      geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
      geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.4)+
      labs(title=title,x="", y = "Difference from Placebo")+
      ylim(-0.22,0.22)+
      th
    ggsave(file_name, plot = p, width = 3.25, height = 2)
  }
  store <- function(m5, m6, m11, m12) {
    est <- bind_rows(
      dam = m5[2:5, ],
      ram = m6[2:5, ],
      dun = m11[2:5, ],
      run = m12[2:5, ],
      .id = "type"
    )
    est$pid <- rep(c(rep("dem", 4), rep("rep", 4)), 2)
    est$x <- c(rep(c(1, 2, 5, 6), 2), rep(c(3, 4, 7, 8), 2))
    return(est)
  }
  
  
  # baseline ATTITUDE
  aca18$w <- 1
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "A: Unweighted", "figs11a.pdf")
  
  
  # study 2 by age
  
  aca18$w <- aca18$w1
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "B: Weighted by Age", "figs11b.pdf")
  
  # study 2 by gender
  
  aca18$w <- aca18$w2
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "C: Weighted by Gender", "figs11c.pdf")
  
  # study 2 by race
  
  aca18$w <- aca18$w3
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "D: Weighted by Race", "figs11d.pdf")
  
  # study 2 by education
  
  
  aca18$w <- aca18$w4
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "E: Weighted by Education", "figs11e.pdf")
  
  # study 2 by income 
  
  
  aca18$w <- aca18$w5
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "F: Weighted by Income", "figs11f.pdf")
  
  
  
  # study 2 by pid strength 
  
  aca18$w <- aca18$w6
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "G: Weighted by PID (7-point)", "figs11g.pdf")
  
  # study 2 by aca support
  
  aca18$w <- aca18$w7
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "H: Weighted by ACA Support", "figs11h.pdf")
  
  
  
  
  # baseline BELIEF
  aca18$w <- 1
  m5<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "A: Unweighted", "figs12a.pdf")
  
  
  # study 2 by age
  
  aca18$w <- aca18$w1
  m5<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "B: Weighted by Age", "figs12b.pdf")
  
  # study 2 by gender
  
  aca18$w <- aca18$w2
  m5<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "C: Weighted by Gender", "figs12c.pdf")
  
  # study 2 by race
  
  aca18$w <- aca18$w3
  m5<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "D: Weighted by Race", "figs12d.pdf")
  
  # study 2 by education
  
  
  aca18$w <- aca18$w4
  m5<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "E: Weighted by Education", "figs12e.pdf")
  
  # study 2 by income 
  
  
  aca18$w <- aca18$w5
  m5<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "F: Weighted by Income", "figs12f.pdf")
  
  
  
  # study 2 by pid strength 
  
  aca18$w <- aca18$w6
  m5<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "G: Weighted by PID (7-point)", "figs12g.pdf")
  
  # study 2 by aca support
  
  aca18$w <- aca18$w7
  m5<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0),weights = w))
  m6<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0),weights = w))
  m11<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1),weights = w))
  m12<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1),weights = w))
  
  est<-store(m5,m6,m11,m12)
  
  plot(est, "H: Weighted by ACA Support", "figs12h.pdf")
  
  
  # Tables S32-S34: Study 2 Randomization Checks ----
  
  aca18$cond10<- factor(as.numeric(aca18$cond)+5*as.numeric(aca18$priming)-1)
  
  aca18$age1 <- aca18$age3/2
  
  
  aca18.all<- aca18%>%
    filter(!is.na(aca0) & 
             !is.na(pid) & 
             !is.na(trump) & 
             !is.na(age1) & 
             !is.na(white) & 
             !is.na(educ2) & 
             !is.na(income)&
             !is.na(cond10))
  
  aca18.dem <- filter(aca18.all, dem == 1)
  aca18.rep <- filter(aca18.all, dem == 0)
  
  models <- list(
    m1 = aca18 %>% filter() %>% lm(aca0 ~ cond10, data = .),
    m2 = aca18 %>% filter(dem == 0) %>% lm(aca0 ~ cond10, data = .),
    m3 = aca18 %>% filter(dem == 1) %>% lm(aca0 ~ cond10, data = .),
    m4 = aca18 %>% filter() %>% lm(trump ~ cond10, data = .),
    m5 = aca18 %>% filter(dem == 0) %>% lm(trump ~ cond10, data = .),
    m6 = aca18 %>% filter(dem == 1) %>% lm(trump ~ cond10, data = .),
    m7 = aca18 %>% filter() %>% lm(str ~ cond10, data = .),
    m8 = aca18 %>% filter(dem == 0) %>% lm(str ~ cond10, data = .),
    m9 = aca18 %>% filter(dem == 1) %>% lm(str ~ cond10, data = .),
    m10 = aca18 %>% filter() %>% lm(age1 ~ cond10, data = .),
    m11 = aca18 %>% filter(dem == 0) %>% lm(age1 ~ cond10, data = .),
    m12 = aca18 %>% filter(dem == 1) %>% lm(age1 ~ cond10, data = .),
    m13 = aca18 %>% filter() %>% lm(female ~ cond10, data = .),
    m14 = aca18 %>% filter(dem == 0) %>% lm(female ~ cond10, data = .),
    m15 = aca18 %>% filter(dem == 1) %>% lm(female ~ cond10, data = .),  
    m16 = aca18 %>% filter() %>% lm(white ~ cond10, data = .),
    m17 = aca18 %>% filter(dem == 0) %>% lm(white ~ cond10, data = .),
    m18 = aca18 %>% filter(dem == 1) %>% lm(white ~ cond10, data = .),  
    m19 = aca18 %>% filter() %>% lm(educ2 ~ cond10, data = .),
    m20 = aca18 %>% filter(dem == 0) %>% lm(educ2 ~ cond10, data = .),
    m21 = aca18 %>% filter(dem == 1) %>% lm(educ2 ~ cond10, data = .),  
    m22 = aca18 %>% filter() %>% lm(income ~ cond10, data = .),
    m23 = aca18 %>% filter(dem == 0) %>% lm(income ~ cond10, data = .),
    m24 = aca18 %>% filter(dem == 1) %>% lm(income ~ cond10, data = .)
  )
  
  
  
  models.hc2 <- list(
    m1 = aca18 %>% filter() %>% lm_robust(aca0 ~ cond10, data = .),
    m2 = aca18 %>% filter(dem == 0) %>% lm_robust(aca0 ~ cond10, data = .),
    m3 = aca18 %>% filter(dem == 1) %>% lm_robust(aca0 ~ cond10, data = .),
    m4 = aca18 %>% filter() %>% lm_robust(trump ~ cond10, data = .),
    m5 = aca18 %>% filter(dem == 0) %>% lm_robust(trump ~ cond10, data = .),
    m6 = aca18 %>% filter(dem == 1) %>% lm_robust(trump ~ cond10, data = .),
    m7 = aca18 %>% filter() %>% lm_robust(str ~ cond10, data = .),
    m8 = aca18 %>% filter(dem == 0) %>% lm_robust(str ~ cond10, data = .),
    m9 = aca18 %>% filter(dem == 1) %>% lm_robust(str ~ cond10, data = .),
    m10 = aca18 %>% filter() %>% lm_robust(age1 ~ cond10, data = .),
    m11 = aca18 %>% filter(dem == 0) %>% lm_robust(age1 ~ cond10, data = .),
    m12 = aca18 %>% filter(dem == 1) %>% lm_robust(age1 ~ cond10, data = .),
    m13 = aca18 %>% filter() %>% lm_robust(female ~ cond10, data = .),
    m14 = aca18 %>% filter(dem == 0) %>% lm_robust(female ~ cond10, data = .),
    m15 = aca18 %>% filter(dem == 1) %>% lm_robust(female ~ cond10, data = .),  
    m16 = aca18 %>% filter() %>% lm_robust(white ~ cond10, data = .),
    m17 = aca18 %>% filter(dem == 0) %>% lm_robust(white ~ cond10, data = .),
    m18 = aca18 %>% filter(dem == 1) %>% lm_robust(white ~ cond10, data = .),  
    m19 = aca18 %>% filter() %>% lm_robust(educ2 ~ cond10, data = .),
    m20 = aca18 %>% filter(dem == 0) %>% lm_robust(educ2 ~ cond10, data = .),
    m21 = aca18 %>% filter(dem == 1) %>% lm_robust(educ2 ~ cond10, data = .),  
    m22 = aca18 %>% filter() %>% lm_robust(income ~ cond10, data = .),
    m23 = aca18 %>% filter(dem == 0) %>% lm_robust(income ~ cond10, data = .),
    m24 = aca18 %>% filter(dem == 1) %>% lm_robust(income ~ cond10, data = .)
  )
  
  
  extract_p_values <- function(model) {
    summary(model)$coefficients[, "Pr(>|t|)"]
  }
  
  
  # Extracting F-statistics and their p-values
  f_stats <- sapply(models.hc2, function(m) sprintf("%.2f", glance(m)$statistic))
  f_p_values <- sapply(models.hc2, function(m) sprintf("%.2f", glance(m)$p.value))
  
  f_p_values2 <- sapply(models.hc2, function(m) glance(m)$p.value)
  
  
  
  # Table S32 
  stargazer(models[1+(0:7)*3], 
            se=starprep(models[1+(0:7)*3]),se_type="HC2",
            digits= 2, digits.extra = 0, keep.stat = c("n"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            star.cutoffs = c(.05),
            column.sep.width = "5pt",
            style = "apsr",
            covariate.labels = c(
              "Amb Civil Con", "Amb Uncivil Con", "Amb Civil Pro", "Amb Uncivil Pro",
              "Uni Control", "Uni Civil Con", "Uni Uncivil Con", "Uni Civil Pro", "Uni Uncivil Pro"
            ),
            add.lines = list(
              c("F (DF = 10)", f_stats[1+(0:7)*3]),
              c("P-value", f_p_values[1+(0:7)*3]),
              c("Covariates", "Pre-", "PID","Trump","Age", "Women", "White", "B.A.", "Earn"),
              c(".         ","Attitude", "","Support",  "45+", "", "","", "50K+")
            ))
  
  # Table S33 
  stargazer(models[2+(0:7)*3], 
            se=starprep(models[2+(0:7)*3]),se_type="HC2",
            digits= 2, digits.extra = 0, keep.stat = c("n"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            star.cutoffs = c(.05),
            column.sep.width = "5pt",
            style = "apsr",
            covariate.labels = c(
              "Amb Civil Con", "Amb Uncivil Con", "Amb Civil Pro", "Amb Uncivil Pro",
              "Uni Control", "Uni Civil Con", "Uni Uncivil Con", "Uni Civil Pro", "Uni Uncivil Pro"
            ),
            add.lines = list(
              c("F (DF = 10)", f_stats[2+(0:7)*3]),
              c("P-value", f_p_values[2+(0:7)*3])
              # c("Covariates", "Pre-", "PID","Trump","Age", "Women", "White", "B.A.", "Earn"),
              # c(".         ","Attitude", "","Support",  "45+", "", "","", "50K+")
            ))
  
  # Table S34
  
  stargazer(models[3+(0:7)*3], 
            se=starprep(models[3+(0:7)*3]),se_type="HC2",
            digits= 2, digits.extra = 0, keep.stat = c("n"),
            dep.var.labels.include = FALSE,
            model.names = FALSE,
            star.cutoffs = c(.05),
            column.sep.width = "5pt",
            style = "apsr",
            covariate.labels = c(
              "Amb Civil Con", "Amb Uncivil Con", "Amb Civil Pro", "Amb Uncivil Pro",
              "Uni Control", "Uni Civil Con", "Uni Uncivil Con", "Uni Civil Pro", "Uni Uncivil Pro"
            ),
            add.lines = list(
              c("F (DF = 10)", f_stats[3+(0:7)*3]),
              c("P-value", f_p_values[3+(0:7)*3])
              # c("Covariates", "Pre-", "PID","Trump","Age", "Women", "White", "B.A.", "Earn"),
              # c(".         ","Attitude", "","Support",  "45+", "", "","", "50K+")
            ))
  
  
  # counting significant p-values
  
  est <- lapply(names(models.hc2), function(name) {
    model <- models.hc2[[name]]
    tidy_model <- tidy(model)
    tidy_model$model <- name
    return(tidy_model)
  })%>%bind_rows()%>%
    filter(term!="(Intercept)")
  
  
  sum(est$p.value < 0.05)/length(est$p.value)
  sum(p.adjust(est$p.value, method = "BH") < 0.05)
  sum(p.adjust(est$p.value, method = "holm") < 0.05)
  
  sum(f_p_values2<.05)
  sum(f_p_values2<.05)/length(f_p_values2<.05)
  sum(p.adjust(f_p_values2, method = "BH") < 0.05)
  sum(p.adjust(f_p_values2, method = "holm") < 0.05)
  
  # Table S35: Study2 joint test of balance ----
  
  joint_tests_18<-bind_rows(
    multinom(factor(cond10)~ aca0+pid+trump+age1+female+white+educ2+income, data = aca18.all)%>%lrtest()%>%tidy(),
    multinom(factor(cond10)~ aca0+pid+trump+age1+female+white+educ2+income, data = aca18.rep)%>%lrtest()%>%tidy(),
    multinom(factor(cond10)~ aca0+pid+trump+age1+female+white+educ2+income, data = aca18.dem)%>%lrtest()%>%tidy()
  )%>%
    filter(term=="factor(cond10) ~ 1")%>%
    mutate(chi.squred = statistic,
           sample = rep(c("All","Republicans","Democrats"),1))%>%
    select(sample,chi.squred,p.value)%>%
    setNames(c("Sample","Chi-Squared (72)", "P-Value"))
  
  
  xtable(joint_tests_18, align = "llcc")%>%print(include.rownames = F)
  
  
  
  # Table S36: Study 2 mean table ----
  
  aca18$cond10 <- factor(as.numeric(aca18$priming)*5+as.numeric(aca18$cond)-1)
  
  a18<-aca18%>%filter(!is.na(cond10))
  
  m1<-lm(aca~cond10,data=subset(a18))
  m2<-lm(aca~cond10+aca0+pid,data=subset(a18))
  m3<-lm(aca~cond10,data=subset(a18,dem==0))
  m4<-lm(aca~cond10+aca0+pid,data=subset(a18,dem==0))
  m5<-lm(aca~cond10,data=subset(a18,dem==1))
  m6<-lm(aca~cond10+aca0+pid,data=subset(a18,dem==1))
  
  m7<-lm(cost~cond10,data=subset(a18))
  m8<-lm(cost~cond10+aca0+pid,data=subset(a18))
  m9<-lm(cost~cond10,data=subset(a18,dem==0))
  m10<-lm(cost~cond10+aca0+pid,data=subset(a18,dem==0))
  m11<-lm(cost~cond10,data=subset(a18,dem==1))
  m12<-lm(cost~cond10+aca0+pid,data=subset(a18,dem==1))
  
  
  ###Estimated means by cond10ition and pid
  p1<-summary(prediction(m1, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m1),calculate_se = TRUE))
  p2<-summary(prediction(m2, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m2),calculate_se = TRUE))
  p3<-summary(prediction(m3, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m3),calculate_se = TRUE))
  p4<-summary(prediction(m4, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m4),calculate_se = TRUE))
  p5<-summary(prediction(m5, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m5),calculate_se = TRUE))
  p6<-summary(prediction(m6, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m6),calculate_se = TRUE))
  p7<-summary(prediction(m7, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m1),calculate_se = TRUE))
  p8<-summary(prediction(m8, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m2),calculate_se = TRUE))
  p9<-summary(prediction(m9, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m3),calculate_se = TRUE))
  p10<-summary(prediction(m10, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m4),calculate_se = TRUE))
  p11<-summary(prediction(m11, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m5),calculate_se = TRUE))
  p12<-summary(prediction(m12, at = list(cond10 = factor(0:9)),vcov = vcovHC(type = "HC2", m6),calculate_se = TRUE))
  
  c1<-p1%>%select(Prediction, SE) # column 1
  c2<-p2%>%select(Prediction, SE) # column 1
  c3<-p3%>%select(Prediction, SE) # column 1
  c4<-p4%>%select(Prediction, SE) # column 1
  c5<-p5%>%select(Prediction, SE) # column 1
  c6<-p6%>%select(Prediction, SE) # column 1
  
  c7<-p7%>%select(Prediction, SE) # column 1
  c8<-p8%>%select(Prediction, SE) # column 1
  c9<-p9%>%select(Prediction, SE) # column 1
  c10<-p10%>%select(Prediction, SE) # column 1
  c11<-p11%>%select(Prediction, SE) # column 1
  c12<-p12%>%select(Prediction, SE) # column 1
  
  
  format_numbers <- function(x, decimals) {
    if (is.numeric(x)) {
      sprintf(paste0("%.", decimals, "f"), x)
    } else {
      x
    }
  }
  
  
  
  rounding <- function(df) {
    df$Prediction <- sapply(df$Prediction, format_numbers, decimals = 3)
    df$SE <- sapply(df$SE, format_numbers, decimals = 3)
    df <- data.frame(lapply(df, factor))
    return(df)
  }
  
  c1to12<-list(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12)
  c1to12_rounded<-lapply(c1to12,rounding)
  
  study2.means<-tibble(
    cond10itions = c("Ambi Control","Ambi Civil Con", "Ambi Uncivil Con", "Ambi Civil Pro","Ambi Uniivil Pro",
                     "Univ Control","Univ Civil Con", "Univ Uncivil Con", "Univ Civil Pro","Univ Uniivil Pro",
                     rep("",10)),
    Entries = c(rep("Mean",10),rep("SE",10)),
    att.all.raw = unlist(c1to12_rounded[[1]], use.names = FALSE),
    att.all.adj = unlist(c1to12_rounded[[2]], use.names = FALSE),
    att.dem.raw = unlist(c1to12_rounded[[3]], use.names = FALSE),
    att.dem.adj = unlist(c1to12_rounded[[4]], use.names = FALSE),
    att.rep.raw = unlist(c1to12_rounded[[5]], use.names = FALSE),
    att.rep.adj = unlist(c1to12_rounded[[6]], use.names = FALSE),
    bel.all.raw = unlist(c1to12_rounded[[7]], use.names = FALSE),
    bel.all.adj = unlist(c1to12_rounded[[8]], use.names = FALSE),
    bel.dem.raw = unlist(c1to12_rounded[[9]], use.names = FALSE),
    bel.dem.adj = unlist(c1to12_rounded[[10]], use.names = FALSE),
    bel.rep.raw = unlist(c1to12_rounded[[11]], use.names = FALSE),
    bel.rep.adj = unlist(c1to12_rounded[[12]], use.names = FALSE),
    order = rep(1:10,2)
  )%>%
    arrange(order)%>%
    select(-order)
  
  print(xtable(study2.means), include.rownames = F)
  
  # Figure S13: Study 2 Results on Attitude with and without Covariates ----
  
  xlab<- c("Con\nCivil\nAmbi","Con\nUncivil\nAmbi","Con\nCivil\nUniv","Con\nUncivil\nUniv",
           "Pro\nCivil\nAmbi","Pro\nUncivil\nAmbi","Pro\nCivil\nUniv","Pro\nUncivil\nUniv")
  
  
  # regressions
  m5<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==0)))
  m6<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==0)))
  m11<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==1&priming==1)))
  m12<-tidy(lm_robust(aca~cond+aca0+pid,data=subset(aca18,dem==0&priming==1)))
  
  m5u<-tidy(lm_robust(aca~cond,data=subset(aca18,dem==1&priming==0)))
  m6u<-tidy(lm_robust(aca~cond,data=subset(aca18,dem==0&priming==0)))
  m11u<-tidy(lm_robust(aca~cond,data=subset(aca18,dem==1&priming==1)))
  m12u<-tidy(lm_robust(aca~cond,data=subset(aca18,dem==0&priming==1)))
  
  m5a<-tidy(lm_robust(aca~cond+aca0+pid+trump+factor(age3)+female+white+income+educ2,data=subset(aca18,dem==1&priming==0)))
  m6a<-tidy(lm_robust(aca~cond+aca0+pid+trump+factor(age3)+female+white+income+educ2,data=subset(aca18,dem==0&priming==0)))
  m11a<-tidy(lm_robust(aca~cond+aca0+pid+trump+factor(age3)+female+white+income+educ2,data=subset(aca18,dem==1&priming==1)))
  m12a<-tidy(lm_robust(aca~cond+aca0+pid+trump+factor(age3)+female+white+income+educ2,data=subset(aca18,dem==0&priming==1)))
  
  
  het3u<-tidy(lm_robust(aca~(cond)*dem,data=subset(aca18,priming==0)))[7:10,]
  het4u<-tidy(lm_robust(aca~(cond)*dem,data=subset(aca18,priming==1)))[7:10,]
  
  het3<-tidy(lm_robust(aca~(cond+aca0+pid)*dem,data=subset(aca18,priming==0)))[9:12,]
  het4<-tidy(lm_robust(aca~(cond+aca0+pid)*dem,data=subset(aca18,priming==1)))[9:12,]
  
  het3a<-tidy(lm_robust(aca~(cond+aca0+pid+trump+factor(age3)+female+white+income+educ2)*dem,data=subset(aca18,priming==0)))[16:19,]
  het4a<-tidy(lm_robust(aca~(cond+aca0+pid+trump+factor(age3)+female+white+income+educ2)*dem,data=subset(aca18,priming==1)))[16:19,]
  
  md<-lm_robust(aca~(cond+aca0+pid)*priming*rep,aca18) 
  mr<-lm_robust(aca~(cond+aca0+pid)*priming*dem,aca18) 
  
  mda<-lm_robust(aca~(cond+aca0+pid+trump+factor(age3)+female+white+income+educ2)*priming*rep,aca18) 
  mra<-lm_robust(aca~(cond+aca0+pid+trump+factor(age3)+female+white+income+educ2)*priming*dem,aca18) 
  
  mdu<-lm_robust(aca~(cond)*priming*rep,aca18) 
  mru<-lm_robust(aca~(cond)*priming*dem,aca18) 
  
  panel_a <- bind_rows(
    damu = m5u[2:5, ],
    ramu = m6u[2:5, ],
    dunu = m11u[2:5, ],
    runu = m12u[2:5, ],
    dam = m5[2:5, ],
    ram = m6[2:5, ],
    dun = m11[2:5, ],
    run = m12[2:5, ],
    dama = m5a[2:5, ],
    rama = m6a[2:5, ],
    duna = m11a[2:5, ],
    runa = m12a[2:5, ],
    .id = "type"
  )
  panel_a$pid <- rep(rep(c(rep("dem", 4), rep("rep", 4)), 2),3)
  panel_a$x <- rep(c(rep(c(1, 2, 5, 6), 2), rep(c(3, 4, 7, 8), 2)),3)
  panel_a$model<- c(rep("A1: No Covariates", 16),
                    rep("A2: Main Specification", 16),
                    rep("A3: Additional Covariates", 16))
  
  
  panel_b <- bind_rows(
    mdu %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    
    md %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    md %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    md %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    md %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    md %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    md %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    md %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    md %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    
    mda %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy()
  )%>%
    mutate(
      x = rep(rep(1:8, 2),3),
      pid = rep(c(rep("dem", 8), rep("rep", 8)),3),
      conf.low = estimate - 1.96 *std.error,
      conf.high= estimate + 1.96 *std.error,
      model = c(rep("B1: No Covariates", 16),
                rep("B2: Main Specification", 16),
                rep("B3: Additional Covariates", 16))
    )
  
  panel_b[c(1, 5, 9, 13,17,21,25,29,33,37,41,45), c(2:6, 9:10)] <- NA
  
  panel_c <- bind_rows(het3u, het4u,het3, het4,het3a, het4a)%>%
    mutate(
      x = rep(c(1, 2, 5, 6, 3, 4, 7, 8),3),
      model = c(rep("C1: No Covariates", 8),
                rep("C2: Main Specification", 8),
                rep("C3: Additional Covariates", 8))
    )
  
  
  panel_d <- bind_rows(
    mru %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond1:priming:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2:priming:dem+cond2:dem-cond1:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond3:priming:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4:priming:dem+cond4:dem-cond3:dem=0")) %>% tidy(),
    
    mr %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond1:priming:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2:priming:dem+cond2:dem-cond1:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond3:priming:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4:priming:dem+cond4:dem-cond3:dem=0")) %>% tidy(),
    
    
    mra %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond1:priming:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2:priming:dem+cond2:dem-cond1:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond3:priming:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4:priming:dem+cond4:dem-cond3:dem=0")) %>% tidy()
  )
  panel_d[c(1,5,9,13,17,21), 2:6] <- NA
  panel_d$x <- rep(1:8,3)
  panel_d$conf.low <- panel_d$estimate - 1.96 * panel_d$std.error
  panel_d$conf.high <- panel_d$estimate + 1.96 * panel_d$std.error
  panel_d$model<- c(rep("D1: No Covariates", 8),
                    rep("D2: Main Specification", 8),
                    rep("D3: Additional Covariates", 8))
  
  th<-  theme_bw()+ theme(panel.grid.major=element_blank(),
                          panel.grid.minor=element_blank(),
                          panel.border=element_rect(colour="black"),
                          axis.title.x=element_blank(),
                          legend.position = c(0.25, 0.2),
                          legend.text=element_text(size=6),
                          legend.key.size = unit(1.5, 'mm'),
                          legend.background = element_rect(fill="transparent"),
                          strip.text = element_text(size = 7),
                          strip.background = element_rect(fill ="white",color = "white",size=1),
                          plot.title = element_blank(),
                          axis.title.y= element_text(size=6),
                          axis.text.x = element_text(color = "black", size=6),
                          axis.text.y = element_text(color = "black", size=6))
  
  
  ggplot(panel_a, aes(x=x, y=estimate,shape=pid,color=pid))+ 
    facet_grid(. ~ model)+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_point(aes(),position=position_dodge(0.5),size=2)+ 
    annotate(geom="text",x =c(1), y=c(0.18),
             label=c("Base"),
             size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(3), y=c(0.18),
             label=c("Contentious"),
             size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(5), y=c(0.18),
             label=c("Base"),
             size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(7), y=c(0.18),
             label=c("Contentious"),
             size=1.6,hjust=0.5)+
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c(16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c("navy","red4"))+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.4)+
    labs(title="title",x="", y = "A: Effects on ACA Attitude")+
    ylim(-0.22,0.22)+th
  ggsave("figs13a.pdf", width = 6.4, height = 2)
  
  
  ggplot(data=panel_b, aes(x=x, y=estimate,shape=pid,color=pid))+ 
    facet_grid(. ~ model)+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_point(aes(),position=position_dodge(0.5),size=2)+ 
    annotate(geom="text",x =c(3), y=c(0.18),
             label=c("Positive =\nWeaker effect of con"),size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(7), y=c(0.18),
             label=c("Positive =\nStronger effect of pro"),size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(3), y=c(-0.18),
             label=c("Negative =\nStronger effect of con"),size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(7), y=c(-0.18),
             label=c("Negative =\nWeaker effect of pro"),size=1.6,hjust=0.5)+
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c(16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c("navy","red4"))+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.4)+
    labs(x="", y = "B: Context Diff in Effects (Contentious - Base)")+
    ylim(-0.22,0.22)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+th+
    theme(legend.position = "none")
  ggsave("figs13b.pdf", width = 6.4, height = 2)
  
  
  
  ggplot(data=panel_c, aes(x=x, y=estimate))+
    facet_grid(. ~ model)+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_point(aes(),size=2,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    guides(shape=guide_legend(title=NULL))+
    labs(title=title,x="", y = "C: Partisan Diff in Effects  (Dem - Rep)")+
    ylim(-0.22,0.22)+
    annotate(geom="text",x =4.5, y=c(-0.195),
             label=c("Negative = Treatment decreases partsan gap"),
             size=1.6,hjust=.5)+
    annotate(geom="text",x =4.5, y=c(0.195),
             label=c("Positive = Treatment increases partsan gap"),
             size=1.6,hjust=.5)+
    th
  ggsave("figs13c.pdf", width = 6.4, height = 2)
  
  
  
  ggplot(data=panel_d, aes(x=x, y=estimate))+
    facet_grid(. ~ model)+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_point(aes(),size=2,shape=1,stroke =.4)+ 
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    guides(shape=guide_legend(title=NULL))+
    labs(title=title,x="", y = "D: Context Diff in Party Diff in Effects")+
    ylim(-0.22,0.22)+
    annotate(geom="text",x =4.5, y=c(-0.195),
             label=c("Negative = Treatment decreases partsan gap more"),
             size=1.6,hjust=.5)+
    annotate(geom="text",x =4.5, y=c(0.195),
             label=c("Positive = Treatment increases partsan gap more"),
             size=1.6,hjust=.5)+
    th
  ggsave("figs13d.pdf", width = 6.4, height = 2)
  
  
  # Figure S14: Study 2 Results on Belief with and without Covariates ----
  
  # regressions
  m5<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==0)))
  m6<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==0)))
  m11<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==1&priming==1)))
  m12<-tidy(lm_robust(cost~cond+aca0+pid,data=subset(aca18,dem==0&priming==1)))
  
  m5u<-tidy(lm_robust(cost~cond,data=subset(aca18,dem==1&priming==0)))
  m6u<-tidy(lm_robust(cost~cond,data=subset(aca18,dem==0&priming==0)))
  m11u<-tidy(lm_robust(cost~cond,data=subset(aca18,dem==1&priming==1)))
  m12u<-tidy(lm_robust(cost~cond,data=subset(aca18,dem==0&priming==1)))
  
  m5a<-tidy(lm_robust(cost~cond+aca0+pid+trump+factor(age3)+female+white+income+educ2,data=subset(aca18,dem==1&priming==0)))
  m6a<-tidy(lm_robust(cost~cond+aca0+pid+trump+factor(age3)+female+white+income+educ2,data=subset(aca18,dem==0&priming==0)))
  m11a<-tidy(lm_robust(cost~cond+aca0+pid+trump+factor(age3)+female+white+income+educ2,data=subset(aca18,dem==1&priming==1)))
  m12a<-tidy(lm_robust(cost~cond+aca0+pid+trump+factor(age3)+female+white+income+educ2,data=subset(aca18,dem==0&priming==1)))
  
  
  het3u<-tidy(lm_robust(cost~(cond)*dem,data=subset(aca18,priming==0)))[7:10,]
  het4u<-tidy(lm_robust(cost~(cond)*dem,data=subset(aca18,priming==1)))[7:10,]
  
  het3<-tidy(lm_robust(cost~(cond+aca0+pid)*dem,data=subset(aca18,priming==0)))[9:12,]
  het4<-tidy(lm_robust(cost~(cond+aca0+pid)*dem,data=subset(aca18,priming==1)))[9:12,]
  
  het3a<-tidy(lm_robust(cost~(cond+aca0+pid+trump+factor(age3)+female+white+income+educ2)*dem,data=subset(aca18,priming==0)))[16:19,]
  het4a<-tidy(lm_robust(cost~(cond+aca0+pid+trump+factor(age3)+female+white+income+educ2)*dem,data=subset(aca18,priming==1)))[16:19,]
  
  md<-lm_robust(cost~(cond+aca0+pid)*priming*rep,aca18) 
  mr<-lm_robust(cost~(cond+aca0+pid)*priming*dem,aca18) 
  
  mda<-lm_robust(cost~(cond+aca0+pid+trump+factor(age3)+female+white+income+educ2)*priming*rep,aca18) 
  mra<-lm_robust(cost~(cond+aca0+pid+trump+factor(age3)+female+white+income+educ2)*priming*dem,aca18) 
  
  mdu<-lm_robust(cost~(cond)*priming*rep,aca18) 
  mru<-lm_robust(cost~(cond)*priming*dem,aca18) 
  
  panel_a <- bind_rows(
    damu = m5u[2:5, ],
    ramu = m6u[2:5, ],
    dunu = m11u[2:5, ],
    runu = m12u[2:5, ],
    dam = m5[2:5, ],
    ram = m6[2:5, ],
    dun = m11[2:5, ],
    run = m12[2:5, ],
    dama = m5a[2:5, ],
    rama = m6a[2:5, ],
    duna = m11a[2:5, ],
    runa = m12a[2:5, ],
    .id = "type"
  )
  panel_a$pid <- rep(rep(c(rep("dem", 4), rep("rep", 4)), 2),3)
  panel_a$x <- rep(c(rep(c(1, 2, 5, 6), 2), rep(c(3, 4, 7, 8), 2)),3)
  panel_a$model<- c(rep("A1: No Covariates", 16),
                    rep("A2: Main Specification", 16),
                    rep("A3: Additional Covariates", 16))
  
  
  panel_b <- bind_rows(
    mdu %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mdu %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    
    md %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    md %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    md %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    md %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    md %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    md %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    md %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    md %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    
    mda %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mda %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2-cond1=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond1:priming=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2-cond1+cond2:priming=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4-cond3=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond3:priming=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4-cond3+cond4:priming=0")) %>% tidy()
  )%>%
    mutate(
      x = rep(rep(1:8, 2),3),
      pid = rep(c(rep("dem", 8), rep("rep", 8)),3),
      conf.low = estimate - 1.96 *std.error,
      conf.high= estimate + 1.96 *std.error,
      model = c(rep("B1: No Covariates", 16),
                rep("B2: Main Specification", 16),
                rep("B3: Additional Covariates", 16))
    )
  
  panel_b[c(1, 5, 9, 13,17,21,25,29,33,37,41,45), c(2:6, 9:10)] <- NA
  
  panel_c <- bind_rows(het3u, het4u,het3, het4,het3a, het4a)%>%
    mutate(
      x = rep(c(1, 2, 5, 6, 3, 4, 7, 8),3),
      model = c(rep("C1: No Covariates", 8),
                rep("C2: Main Specification", 8),
                rep("C3: Additional Covariates", 8))
    )
  
  
  panel_d <- bind_rows(
    mru %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond1:priming:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond2:priming:dem+cond2:dem-cond1:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond3:priming:dem=0")) %>% tidy(),
    mru %>% glht(linfct = c("cond4:priming:dem+cond4:dem-cond3:dem=0")) %>% tidy(),
    
    mr %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond1:priming:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond2:priming:dem+cond2:dem-cond1:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond3:priming:dem=0")) %>% tidy(),
    mr %>% glht(linfct = c("cond4:priming:dem+cond4:dem-cond3:dem=0")) %>% tidy(),
    
    
    mra %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2:dem-cond1:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond1:priming:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond2:priming:dem+cond2:dem-cond1:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4:dem-cond3:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond3:priming:dem=0")) %>% tidy(),
    mra %>% glht(linfct = c("cond4:priming:dem+cond4:dem-cond3:dem=0")) %>% tidy()
  )
  panel_d[c(1,5,9,13,17,21), 2:6] <- NA
  panel_d$x <- rep(1:8,3)
  panel_d$conf.low <- panel_d$estimate - 1.96 * panel_d$std.error
  panel_d$conf.high <- panel_d$estimate + 1.96 * panel_d$std.error
  panel_d$model<- c(rep("D1: No Covariates", 8),
                    rep("D2: Main Specification", 8),
                    rep("D3: Additional Covariates", 8))
  
  th<-  theme_bw()+ theme(panel.grid.major=element_blank(),
                          panel.grid.minor=element_blank(),
                          panel.border=element_rect(colour="black"),
                          axis.title.x=element_blank(),
                          legend.position = c(0.25, 0.2),
                          legend.text=element_text(size=6),
                          legend.key.size = unit(1.5, 'mm'),
                          legend.background = element_rect(fill="transparent"),
                          strip.text = element_text(size = 7),
                          strip.background = element_rect(fill ="white",color = "white",size=1),
                          plot.title = element_blank(),
                          axis.title.y= element_text(size=6),
                          axis.text.x = element_text(color = "black", size=6),
                          axis.text.y = element_text(color = "black", size=6))
  
  
  ggplot(panel_a, aes(x=x, y=estimate,shape=pid,color=pid))+ 
    facet_grid(. ~ model)+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_point(aes(),position=position_dodge(0.5),size=2)+ 
    annotate(geom="text",x =c(1), y=c(0.18),
             label=c("Base"),
             size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(3), y=c(0.18),
             label=c("Contentious"),
             size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(5), y=c(0.18),
             label=c("Base"),
             size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(7), y=c(0.18),
             label=c("Contentious"),
             size=1.6,hjust=0.5)+
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c(16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c("navy","red4"))+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.4)+
    labs(title="title",x="", y = "A: Effects on ACA Attitude")+
    ylim(-0.22,0.22)+th
  ggsave("figs14a.pdf", width = 6.4, height = 2)
  
  
  ggplot(data=panel_b, aes(x=x, y=estimate,shape=pid,color=pid))+ 
    facet_grid(. ~ model)+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.005, color = "white")+
    geom_point(aes(),position=position_dodge(0.5),size=2)+ 
    annotate(geom="text",x =c(3), y=c(0.18),
             label=c("Positive =\nWeaker effect of con"),size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(7), y=c(0.18),
             label=c("Positive =\nStronger effect of pro"),size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(3), y=c(-0.18),
             label=c("Negative =\nStronger effect of con"),size=1.6,hjust=0.5)+
    annotate(geom="text",x =c(7), y=c(-0.18),
             label=c("Negative =\nWeaker effect of pro"),size=1.6,hjust=0.5)+
    scale_shape_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c(16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("dem","rep"),
                       labels = c("Dem", "Rep"),
                       values=c("navy","red4"))+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.4)+
    labs(x="", y = "B: Context Diff in Effects (Contentious - Base)")+
    ylim(-0.22,0.22)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+th+
    theme(legend.position = "none")
  ggsave("figs14b.pdf", width = 6.4, height = 2)
  
  
  
  ggplot(data=panel_c, aes(x=x, y=estimate))+
    facet_grid(. ~ model)+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_point(aes(),size=2,shape=1,stroke =.4)+ 
    theme_bw()+
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    guides(shape=guide_legend(title=NULL))+
    labs(title=title,x="", y = "C: Partisan Diff in Effects  (Dem - Rep)")+
    ylim(-0.22,0.22)+
    annotate(geom="text",x =4.5, y=c(-0.195),
             label=c("Negative = Treatment decreases partsan gap"),
             size=1.6,hjust=.5)+
    annotate(geom="text",x =4.5, y=c(0.195),
             label=c("Positive = Treatment increases partsan gap"),
             size=1.6,hjust=.5)+
    th
  ggsave("figs14c.pdf", width = 6.4, height = 2)
  
  
  
  ggplot(data=panel_d, aes(x=x, y=estimate))+
    facet_grid(. ~ model)+
    geom_rect(aes(xmin = 0.5, xmax=1.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_rect(aes(xmin = 4.5, xmax=5.5, ymin=-Inf, ymax=Inf), alpha = 0.01, color = "white")+
    geom_point(aes(),size=2,shape=1,stroke =.4)+ 
    scale_x_continuous(breaks = 1:8,
                       labels=xlab, limits = c(0.5,8.5), expand = c(0, 0))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.5), size=0.2)+
    guides(shape=guide_legend(title=NULL))+
    labs(title=title,x="", y = "D: Context Diff in Party Diff in Effects")+
    ylim(-0.22,0.22)+
    annotate(geom="text",x =4.5, y=c(-0.195),
             label=c("Negative = Treatment decreases partsan gap more"),
             size=1.6,hjust=.5)+
    annotate(geom="text",x =4.5, y=c(0.195),
             label=c("Positive = Treatment increases partsan gap more"),
             size=1.6,hjust=.5)+
    th
  ggsave("figs14d.pdf", width = 6.4, height = 2)
  
  
  
  # Figure 15 Comparing Study 2 Results on Attitude vs Belief ----
  
  
  md<-lm_robust(aca~(cond+aca0+pid)*priming*rep,aca18) 
  uncon1<-md%>%glht(linfct="(cond3+cond3:rep-cond1)/2=0")%>%tidy() 
  uncon2<-md%>%glht(linfct="(cond4+cond4:rep-cond2)/2=0")%>%tidy() 
  uncon3<-md%>%glht(linfct="(cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming)/2=0")%>%tidy() 
  uncon4<-md%>%glht(linfct="(cond4+cond4:rep+cond4:priming+cond4:priming:rep-cond2-cond2:priming)/2=0")%>%tidy() 
  uncon5<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  uncon6<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3:priming+cond3:priming:rep-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming-2*cond3-2*cond3:rep+2*cond1)/6=0")%>%tidy() 
  attitude.uncongenial<-bind_rows(uncon1,uncon2,uncon3,uncon4,uncon5,uncon6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  xtable::xtable(attitude.uncongenial)
  # combined together, affective environments undercut the effect of counter information by 4 percentgage points (row 6)
  
  
  #### Congenial info effects across different contexts
  mr<-lm_robust(aca~(cond+aca0+pid)*priming*dem,aca18) 
  conge1<-mr%>%glht(linfct="(cond3+cond3:dem-cond1)/2=0")%>%tidy() 
  conge2<-mr%>%glht(linfct="(cond4+cond4:dem-cond2)/2=0")%>%tidy() 
  conge3<-mr%>%glht(linfct="(cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming)/2=0")%>%tidy() 
  conge4<-mr%>%glht(linfct="(cond4+cond4:dem+cond4:priming+cond4:priming:dem-cond2-cond2:priming)/2=0")%>%tidy() 
  conge5<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  conge6<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3:priming+cond3:priming:dem-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming-2*cond3-2*cond3:dem+2*cond1)/6=0")%>%tidy() 
  # difference in cognenial info effect in affective environ vs. non-affective environ
  attitude.congenial<-bind_rows(conge1,conge2,conge3,conge4,conge5,conge6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  
  
  
  attitude.conuncon<-bind_rows(attitude.congenial, attitude.uncongenial)[c(1,5,6,7,11,12),]%>%
    bind_cols(info=c(rep("congenial",3),rep("uncongenial",3)), x = c(1,2,3,1,2,3))
  
  
  attitude.conuncon$conf.low<-attitude.conuncon$estimate-1.96*attitude.conuncon$std.error
  attitude.conuncon$conf.high<-attitude.conuncon$estimate+1.96*attitude.conuncon$std.error
  
  attitude.conuncon$conf.low2<-attitude.conuncon$estimate-1.645*attitude.conuncon$std.error
  attitude.conuncon$conf.high2<-attitude.conuncon$estimate+1.645*attitude.conuncon$std.error
  
  
  mr%>%glht(linfct=c("(2*cond2:dem-2*cond1:dem+
   cond1:priming:dem+
   cond2:priming:dem+
   2*cond4:dem-2*cond3:dem+
   cond3:priming:dem+
   cond4:priming:dem)/6=0"))%>%tidy()
  
  md<-lm_robust(cost~(cond+aca0+pid)*priming*rep,aca18) 
  uncon1<-md%>%glht(linfct="(cond3+cond3:rep-cond1)/2=0")%>%tidy() 
  uncon2<-md%>%glht(linfct="(cond4+cond4:rep-cond2)/2=0")%>%tidy() 
  uncon3<-md%>%glht(linfct="(cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming)/2=0")%>%tidy() 
  uncon4<-md%>%glht(linfct="(cond4+cond4:rep+cond4:priming+cond4:priming:rep-cond2-cond2:priming)/2=0")%>%tidy() 
  uncon5<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3+cond3:rep+cond3:priming+cond3:priming:rep-cond1-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  uncon6<-md%>%glht(linfct="(2*cond4+2*cond4:rep-2*cond2+cond3:priming+cond3:priming:rep-cond1:priming+cond4:priming+cond4:priming:rep-cond2:priming-2*cond3-2*cond3:rep+2*cond1)/6=0")%>%tidy() 
  belief.uncongenial<-bind_rows(uncon1,uncon2,uncon3,uncon4,uncon5,uncon6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  xtable::xtable(belief.uncongenial)
  # combined together, affective environments undercut the effect of counter information by 4 percentgage points (row 6)
  
  
  #### Congenial info effects across different contexts
  mr<-lm_robust(cost~(cond+aca0+pid)*priming*dem,aca18) 
  conge1<-mr%>%glht(linfct="(cond3+cond3:dem-cond1)/2=0")%>%tidy() 
  conge2<-mr%>%glht(linfct="(cond4+cond4:dem-cond2)/2=0")%>%tidy() 
  conge3<-mr%>%glht(linfct="(cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming)/2=0")%>%tidy() 
  conge4<-mr%>%glht(linfct="(cond4+cond4:dem+cond4:priming+cond4:priming:dem-cond2-cond2:priming)/2=0")%>%tidy() 
  conge5<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3+cond3:dem+cond3:priming+cond3:priming:dem-cond1-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming)/6=0")%>%tidy() 
  # averge effect of cognenial info in affective environ
  conge6<-mr%>%glht(linfct="(2*cond4+2*cond4:dem-2*cond2+cond3:priming+cond3:priming:dem-cond1:priming+cond4:priming+cond4:priming:dem-cond2:priming-2*cond3-2*cond3:dem+2*cond1)/6=0")%>%tidy() 
  # difference in cognenial info effect in affective environ vs. non-affective environ
  belief.congenial<-bind_rows(conge1,conge2,conge3,conge4,conge5,conge6)%>%
    bind_cols(estimand=c("baseline","uncivil","uni","uncivil&uni","affective avg","baseline vs affect"))
  
  
  
  belief.conuncon<-bind_rows(belief.congenial, belief.uncongenial)[c(1,5,6,7,11,12),]%>%
    bind_cols(info=c(rep("congenial",3),rep("uncongenial",3)), x = c(1,2,3,1,2,3))
  
  
  belief.conuncon$conf.low<-belief.conuncon$estimate-1.96*belief.conuncon$std.error
  belief.conuncon$conf.high<-belief.conuncon$estimate+1.96*belief.conuncon$std.error
  
  belief.conuncon$conf.low2<-belief.conuncon$estimate-1.645*belief.conuncon$std.error
  belief.conuncon$conf.high2<-belief.conuncon$estimate+1.645*belief.conuncon$std.error
  
  
  
  
  
  
  
  aca18_stacked<-rbind(
    aca18%>%mutate(dv_belief = 0, outcome = aca, id = 1:nrow(aca18))%>%select(dv_belief,id,outcome,cond,aca0,pid,priming,dem,rep),
    aca18%>%mutate(dv_belief = 1, outcome = cost, id = 1:nrow(aca18))%>%select(dv_belief,id,outcome,cond,aca0,pid,priming,dem,rep)
  )
  
  md_stacked<-lm_robust(outcome~(cond+aca0+pid)*priming*rep*dv_belief,aca18_stacked, clusters = id) 
  
  
  th<-theme(panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            axis.title.x=element_blank(),
            legend.position = c(0.85, 0.25),
            legend.text=element_text(size=7),
            legend.key.size = unit(1.5, 'mm'),
            legend.background = element_rect(fill="transparent"),
            plot.title = element_text(size=9,hjust=0.5),
            axis.title.y= element_text(size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=7))
  
  
  
  
  
  
  
  
  
  ggplot(data=attitude.conuncon[c(-3,-6),], aes(x=x, y=estimate, color=info))+ 
    geom_point(aes(),size=3,stroke =.4,position=position_dodge(0.1))+ 
    geom_line(position=position_dodge(0.1), size = 0.4, alpha = 0.7, linetype = "dashed")+
    theme_bw()+
    scale_color_manual(name = c(""),
                       breaks=c("congenial","uncongenial"),
                       labels = c("Congenial", "Uncongenial"),
                       values=c("black","#E7A500"))+
    scale_x_continuous(breaks = 1:2, limits = c(.5,2.5),
                       labels=c("Baseline\n(Civil and Ambivalent)","Contentious\n(Uncivil, Univalent, or both)"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.1), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.1), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(A1) Pooled Effects on Attitude",x="", y = "Effects otoward Information")+
    annotate(geom="text",x =1.5, y=c(0.068,0.036),
             label=c("+0.03","-0.04"),
             color=c("black","#E7A500"),size=2.4,hjust=.5)+
    th+  theme(legend.position = c(0.18, 0.9))+
    ylim(0, .13)
  ggsave("figs15a1.pdf",width=3.25,height=2.5)
  
  
  ggplot(data=attitude.conuncon[c(3,6),], aes(x=x, y=estimate, color=info))+ 
    geom_point(aes(),size=3,stroke =.4)+ 
    theme_bw()+
    scale_color_manual(name = c(""),
                       breaks=c("congenial","uncongenial"),
                       labels = c("Congenial", "Uncongenial"),
                       values=c("black","#E7A500"))+
    scale_x_continuous(breaks = 3, limits = c(2.5,3.5),
                       labels=c("Contentious vs. Baseline\n"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(B1) Difference in Effects on Attitude",x="", y = "Difference in Effects (Contentious - Baseline)")+
    th+  theme(legend.position = c(0.25, 0.2))+  ylim(-0.1,.1)
  ggsave("figs15b1.pdf",width=3.25,height=2.5)
  
  
  
  ggplot(data=belief.conuncon[c(-3,-6),], aes(x=x, y=estimate, color=info))+ 
    geom_point(aes(),size=3,stroke =.4,position=position_dodge(0.1))+ 
    geom_line(position=position_dodge(0.1), size = 0.4, alpha = 0.7, linetype = "dashed")+
    theme_bw()+
    scale_color_manual(name = c(""),
                       breaks=c("congenial","uncongenial"),
                       labels = c("Congenial", "Uncongenial"),
                       values=c("black","#E7A500"))+
    scale_x_continuous(breaks = 1:2, limits = c(.5,2.5),
                       labels=c("Baseline\n(Civil and Ambivalent)","Contentious\n(Uncivil, Univalent, or both)"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.1), size=0.2)+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2),position=position_dodge(0.1), size=0.6, alpha=0.6)+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(A2) Pooled Effects on Belief",x="", y = "Effects on Belief toward Information")+
    annotate(geom="text",x =1.5, y=c(0.095,0.075),
             label=c("+0.01","-0.04"),
             color=c("black","#E7A500"),size=2.4,hjust=.5)+
    th+  theme(legend.position = c(0.18, 0.2))
  ggsave("figs15a2.pdf",width=3.25,height=2.5)
  
  
  ggplot(data=belief.conuncon[c(3,6),], aes(x=x, y=estimate, color=info))+ 
    geom_point(aes(),size=3,stroke =.4,position=position_dodge(0.1))+ 
    theme_bw()+
    scale_color_manual(name = c(""),
                       breaks=c("congenial","uncongenial"),
                       labels = c("Congenial", "Uncongenial"),
                       values=c("black","#E7A500"))+
    scale_x_continuous(breaks = 3, limits = c(2.5,3.5),
                       labels=c("Contentious vs. Baseline\n"))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high), size=0.2,position=position_dodge(0.1))+
    geom_linerange(aes(ymin = conf.low2, ymax = conf.high2), size=0.6, alpha=0.6,position=position_dodge(0.1))+
    guides(shape=guide_legend(title=NULL))+
    labs(title="(B2) Difference in Effects on Belief",x="", y = "Difference in Effects (Contentious - Baseline)")+
    th+  theme(legend.position = c(0.25, 0.2))+
    ylim(-0.1,.1)
  ggsave("figs15b2.pdf",width=3.25,height=2.5)
  
  
  
  
  # Figure S16 ----
  
  
  
  m1<-lm(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca))
  m2<-lm(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca,dem==1))
  m3<-lm(aca~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca,dem==0))
  m4<-lm(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca))
  m5<-lm(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca,dem==1))
  m6<-lm(cost~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca,dem==0))
  ###Estimated means by condition and pid
  p1<-summary(prediction(m1, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m1),calculate_se = TRUE))
  p2<-summary(prediction(m2, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m2),calculate_se = TRUE))
  p3<-summary(prediction(m3, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m3),calculate_se = TRUE))
  p4<-summary(prediction(m4, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m4),calculate_se = TRUE))
  p5<-summary(prediction(m5, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m5),calculate_se = TRUE))
  p6<-summary(prediction(m6, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m6),calculate_se = TRUE))
  
  ###storing estimated means
  paca1<-bind_rows(all=p1,dem=p2,rep=p3,.id="pid")
  pcost1<-bind_rows(tall=p4,dem=p5,rep=p6,.id="pid")
  
  ###turning estimated means into prior odds/posterior odds to calculate bayes factor
  paca1$prior[1:5]=paca1$Prediction[1]/(1-paca1$Prediction[1])
  paca1$prior[6:10]=paca1$Prediction[6]/(1-paca1$Prediction[6])
  paca1$prior[11:15]=paca1$Prediction[11]/(1-paca1$Prediction[11])
  paca1$post=paca1$Prediction/(1-paca1$Prediction)
  paca1$probf=paca1$post/paca1$prior
  paca1$conbf=paca1$prior/paca1$post
  
  pcost1$prior[1:5]=pcost1$Prediction[1]/(1-pcost1$Prediction[1])
  pcost1$prior[6:10]=pcost1$Prediction[6]/(1-pcost1$Prediction[6])
  pcost1$prior[11:15]=pcost1$Prediction[11]/(1-pcost1$Prediction[11])
  pcost1$post=pcost1$Prediction/(1-pcost1$Prediction)
  pcost1$probf=pcost1$post/pcost1$prior
  pcost1$conbf=pcost1$prior/pcost1$post
  
  
  m1<-lm(obamahc~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca))
  m2<-lm(obamahc~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca,dem==1))
  m3<-lm(obamahc~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca,dem==0))
  m4<-lm(obama~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca))
  m5<-lm(obama~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca,dem==1))
  m6<-lm(obama~cond+w1aca+w1cost+pid+w1obama+w1obamahc,data=subset(aca,dem==0))
  p1<-summary(prediction(m1, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m1),calculate_se = TRUE))
  p2<-summary(prediction(m2, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m2),calculate_se = TRUE))
  p3<-summary(prediction(m3, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m3),calculate_se = TRUE))
  p4<-summary(prediction(m4, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m4),calculate_se = TRUE))
  p5<-summary(prediction(m5, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m5),calculate_se = TRUE))
  p6<-summary(prediction(m6, at = list(cond = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m6),calculate_se = TRUE))
  
  
  ###storing estimated means
  pobamahc1<-bind_rows(all=p1,dem=p2,rep=p3,.id="pid")
  pobama1<-bind_rows(tall=p4,dem=p5,rep=p6,.id="pid")
  
  ###turning estimated means into prior odds/posterior odds to calculate bayes factor
  pobamahc1$prior[1:5]=pobamahc1$Prediction[1]/(1-pobamahc1$Prediction[1])
  pobamahc1$prior[6:10]=pobamahc1$Prediction[6]/(1-pobamahc1$Prediction[6])
  pobamahc1$prior[11:15]=pobamahc1$Prediction[11]/(1-pobamahc1$Prediction[11])
  pobamahc1$post=pobamahc1$Prediction/(1-pobamahc1$Prediction)
  pobamahc1$probf=pobamahc1$post/pobamahc1$prior
  pobamahc1$conbf=pobamahc1$prior/pobamahc1$post
  
  pobama1$prior[1:5]=pobama1$Prediction[1]/(1-pobama1$Prediction[1])
  pobama1$prior[6:10]=pobama1$Prediction[6]/(1-pobama1$Prediction[6])
  pobama1$prior[11:15]=pobama1$Prediction[11]/(1-pobama1$Prediction[11])
  pobama1$post=pobama1$Prediction/(1-pobama1$Prediction)
  pobama1$probf=pobama1$post/pobama1$prior
  pobama1$conbf=pobama1$prior/pobama1$post
  
  
  
  
  ###Re-running regression models ("lm" command to work with prediction function)
  m1<-lm(cost~cond2+aca0+pid,data=subset(aca18,priming==0))
  m2<-lm(cost~cond2+aca0+pid,data=subset(aca18,dem==1&priming==0))
  m3<-lm(cost~cond2+aca0+pid,data=subset(aca18,dem==0&priming==0))
  m4<-lm(aca~cond2+aca0+pid,data=subset(aca18,priming==0))
  m5<-lm(aca~cond2+aca0+pid,data=subset(aca18,dem==1&priming==0))
  m6<-lm(aca~cond2+aca0+pid,data=subset(aca18,dem==0&priming==0))
  m7<-lm(cost~cond2+aca0+pid,data=subset(aca18,priming==1))
  m8<-lm(cost~cond2+aca0+pid,data=subset(aca18,dem==1&priming==1))
  m9<-lm(cost~cond2+aca0+pid,data=subset(aca18,dem==0&priming==1))
  m10<-lm(aca~cond2+aca0+pid,data=subset(aca18,priming==1))
  m11<-lm(aca~cond2+aca0+pid,data=subset(aca18,dem==1&priming==1))
  m12<-lm(aca~cond2+aca0+pid,data=subset(aca18,dem==0&priming==1))
  
  
  ###Estimated means by cond2ition and pid
  p1<-summary(prediction(m1, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m1),calculate_se = TRUE))
  p2<-summary(prediction(m2, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m2),calculate_se = TRUE))
  p3<-summary(prediction(m3, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m3),calculate_se = TRUE))
  p4<-summary(prediction(m4, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m4),calculate_se = TRUE))
  p5<-summary(prediction(m5, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m5),calculate_se = TRUE))
  p6<-summary(prediction(m6, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m6),calculate_se = TRUE))
  p7<-summary(prediction(m7, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m7),calculate_se = TRUE))
  p8<-summary(prediction(m8, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m8),calculate_se = TRUE))
  p9<-summary(prediction(m9, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m9),calculate_se = TRUE))
  p10<-summary(prediction(m10, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m10),calculate_se = TRUE))
  p11<-summary(prediction(m11, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m11),calculate_se = TRUE))
  p12<-summary(prediction(m12, at = list(cond2 = c("0", "1","2","3","4")),vcov = vcovHC(type = "HC2", m12),calculate_se = TRUE))
  
  ###storing estimated means
  pcost3<-bind_rows(all=p1,dem=p2,rep=p3,.id="pid")
  paca3<-bind_rows(all=p4,dem=p5,rep=p6,.id="pid")
  
  ###turning estimated means into prior odds/posterior odds to calculate bayes factor
  paca3$prior[1:5]=paca3$Prediction[1]/(1-paca3$Prediction[1])
  paca3$prior[6:10]=paca3$Prediction[6]/(1-paca3$Prediction[6])
  paca3$prior[11:15]=paca3$Prediction[11]/(1-paca3$Prediction[11])
  paca3$post=paca3$Prediction/(1-paca3$Prediction)
  paca3$probf=paca3$post/paca3$prior
  paca3$conbf=paca3$prior/paca3$post
  
  pcost3$prior[1:5]=pcost3$Prediction[1]/(1-pcost3$Prediction[1])
  pcost3$prior[6:10]=pcost3$Prediction[6]/(1-pcost3$Prediction[6])
  pcost3$prior[11:15]=pcost3$Prediction[11]/(1-pcost3$Prediction[11])
  pcost3$post=pcost3$Prediction/(1-pcost3$Prediction)
  pcost3$probf=pcost3$post/pcost3$prior
  pcost3$conbf=pcost3$prior/pcost3$post
  
  
  
  pcost4<-bind_rows(all=p7,dem=p8,rep=p9,.id="pid")
  paca4<-bind_rows(all=p10,dem=p11,rep=p12,.id="pid")
  paca4$prior[1:5]=paca4$Prediction[1]/(1-paca4$Prediction[1])
  paca4$prior[6:10]=paca4$Prediction[6]/(1-paca4$Prediction[6])
  paca4$prior[11:15]=paca4$Prediction[11]/(1-paca4$Prediction[11])
  paca4$post=paca4$Prediction/(1-paca4$Prediction)
  paca4$probf=paca4$post/paca4$prior
  paca4$conbf=paca4$prior/paca4$post
  
  pcost4$prior[1:5]=pcost4$Prediction[1]/(1-pcost4$Prediction[1])
  pcost4$prior[6:10]=pcost4$Prediction[6]/(1-pcost4$Prediction[6])
  pcost4$prior[11:15]=pcost4$Prediction[11]/(1-pcost4$Prediction[11])
  pcost4$post=pcost4$Prediction/(1-pcost4$Prediction)
  pcost4$probf=pcost4$post/pcost4$prior
  pcost4$conbf=pcost4$prior/pcost4$post
  
  
  
  
  results<-data.frame(
    y=c(paca1$Prediction[7]-paca1$Prediction[6], #Study 1 Strong con on ACA (Dem)
        paca1$Prediction[8]-paca1$Prediction[6], #Study 1 Weak con on ACA (Dem)
        paca1$Prediction[14]-paca1$Prediction[11], #Study 1 weam pro on ACA (Rep)
        paca1$Prediction[15]-paca1$Prediction[11], #Study 1 strong pro on ACA (Rep)
        pcost1$Prediction[7]-pcost1$Prediction[6], #Study 1 Strong con on cost (Dem)
        pcost1$Prediction[8]-pcost1$Prediction[6], #Study 1 Weak con on cost (Dem)
        pcost1$Prediction[14]-pcost1$Prediction[11], #Study 1 weam pro on cost (Rep)
        pcost1$Prediction[15]-pcost1$Prediction[11], #Study 1 strong pro on cost (Rep)
  
        pobamahc1$Prediction[7]-pobamahc1$Prediction[6], #Study 1 Strong con on obamahc (Dem)
        pobamahc1$Prediction[8]-pobamahc1$Prediction[6], #Study 1 Weak con on obamahc (Dem)
        pobamahc1$Prediction[14]-pobamahc1$Prediction[11], #Study 1 weam pro on obamahc (Rep)
        pobamahc1$Prediction[15]-pobamahc1$Prediction[11], #Study 1 strong pro on obamahc (Rep)
        pobama1$Prediction[7]-pobama1$Prediction[6], #Study 1 Strong con on obama (Dem)
        pobama1$Prediction[8]-pobama1$Prediction[6], #Study 1 Weak con on obama (Dem)
        pobama1$Prediction[14]-pobama1$Prediction[11], #Study 1 weam pro on obama (Rep)
        pobama1$Prediction[15]-pobama1$Prediction[11], #Study 1 strong pro on obama (Rep)
  
        paca3$Prediction[7]-paca3$Prediction[6], #Study 4 civil con aca (Den)
        pcost3$Prediction[7]-pcost3$Prediction[6], #Study 4 civil con cost (Dem)
        paca3$Prediction[13]-paca3$Prediction[11], #Study 4 civil pro aca (Rep)
        pcost3$Prediction[13]-pcost3$Prediction[11], #Study 4 civil pro cost (Rep)
        paca3$Prediction[9]-paca3$Prediction[6], #Study 4 uncivil con aca (dem)
        pcost3$Prediction[9]-pcost3$Prediction[6], #Study 4 uncivil con cost (dem)
        paca3$Prediction[15]-paca3$Prediction[11], #Study 4 uncivil pro aca (Rep)
        pcost3$Prediction[15]-pcost3$Prediction[11], #Study 4 uncivil pro cost (Rep)
        paca4$Prediction[7]-paca4$Prediction[6], #Study 4 Univ  civil con aca (Den)
        pcost4$Prediction[7]-pcost4$Prediction[6], #Study 4 Univ  civil con cost (Dem)
        paca4$Prediction[13]-paca4$Prediction[11], #Study 4 Univ  civil pro aca (Rep)
        pcost4$Prediction[13]-pcost4$Prediction[11], #Study 4 Univ  civil pro cost (Rep)
        paca4$Prediction[9]-paca4$Prediction[6], #Study 4 Univ  uncivil con aca (dem)
        pcost4$Prediction[9]-pcost4$Prediction[6], #Study 4 Univ  uncivil con cost (dem)
        paca4$Prediction[15]-paca4$Prediction[11], #Study 4 Univ  uncivil pro aca (Rep)
        pcost4$Prediction[15]-pcost4$Prediction[11] #Study 4 Univ  uncivil pro cost (Rep)
    ),
    x=c((paca1$Prediction[6]*(1/paca1$conbf[12]))/(paca1$Prediction[6]*(1/paca1$conbf[12])+(1-paca1$Prediction[6]))-paca1$Prediction[6], # simulating Study 1 strong con effect on attitude among Dem using Dem's prior and Rep's bayes factor
        (paca1$Prediction[6]*(1/paca1$conbf[13]))/(paca1$Prediction[6]*(1/paca1$conbf[13])+(1-paca1$Prediction[6]))-paca1$Prediction[6],
        (paca1$Prediction[11]*paca1$probf[9])/(paca1$Prediction[11]*paca1$probf[9]+(1-paca1$Prediction[11]))-paca1$Prediction[11],
        (paca1$Prediction[11]*paca1$probf[10])/(paca1$Prediction[11]*paca1$probf[10]+(1-paca1$Prediction[11]))-paca1$Prediction[11],
        (pcost1$Prediction[6]*(1/pcost1$conbf[12]))/(pcost1$Prediction[6]*(1/pcost1$conbf[12])+(1-pcost1$Prediction[6]))-pcost1$Prediction[6],
        (pcost1$Prediction[6]*(1/pcost1$conbf[13]))/(pcost1$Prediction[6]*(1/pcost1$conbf[13])+(1-pcost1$Prediction[6]))-pcost1$Prediction[6],
        (pcost1$Prediction[11]*pcost1$probf[9])/(pcost1$Prediction[11]*pcost1$probf[9]+(1-pcost1$Prediction[11]))-pcost1$Prediction[11],
        (pcost1$Prediction[11]*pcost1$probf[10])/(pcost1$Prediction[11]*pcost1$probf[10]+(1-pcost1$Prediction[11]))-pcost1$Prediction[11],
        (pobamahc1$Prediction[6]*(1/pobamahc1$conbf[12]))/(pobamahc1$Prediction[6]*(1/pobamahc1$conbf[12])+(1-pobamahc1$Prediction[6]))-pobamahc1$Prediction[6],
        (pobamahc1$Prediction[6]*(1/pobamahc1$conbf[13]))/(pobamahc1$Prediction[6]*(1/pobamahc1$conbf[13])+(1-pobamahc1$Prediction[6]))-pobamahc1$Prediction[6],
        (pobamahc1$Prediction[11]*pobamahc1$probf[9])/(pobamahc1$Prediction[11]*pobamahc1$probf[9]+(1-pobamahc1$Prediction[11]))-pobamahc1$Prediction[11],
        (pobamahc1$Prediction[11]*pobamahc1$probf[10])/(pobamahc1$Prediction[11]*pobamahc1$probf[10]+(1-pobamahc1$Prediction[11]))-pobamahc1$Prediction[11],
        (pobama1$Prediction[6]*(1/pobama1$conbf[12]))/(pobama1$Prediction[6]*(1/pobama1$conbf[12])+(1-pobama1$Prediction[6]))-pobama1$Prediction[6],
        (pobama1$Prediction[6]*(1/pobama1$conbf[13]))/(pobama1$Prediction[6]*(1/pobama1$conbf[13])+(1-pobama1$Prediction[6]))-pobama1$Prediction[6],
        (pobama1$Prediction[11]*pobama1$probf[9])/(pobama1$Prediction[11]*pobama1$probf[9]+(1-pobama1$Prediction[11]))-pobama1$Prediction[11],
        (pobama1$Prediction[11]*pobama1$probf[10])/(pobama1$Prediction[11]*pobama1$probf[10]+(1-pobama1$Prediction[11]))-pobama1$Prediction[11],
        (paca3$Prediction[6]*(1/paca3$conbf[12]))/(paca3$Prediction[6]*(1/paca3$conbf[12])+(1-paca3$Prediction[6]))-paca3$Prediction[6], #Study 4 civil con aca (Den)
        (pcost3$Prediction[6]*(1/pcost3$conbf[12]))/(pcost3$Prediction[6]*(1/pcost3$conbf[12])+(1-pcost3$Prediction[6]))-pcost3$Prediction[6], #Study 4 civil con cost (Dem)
        (paca3$Prediction[11]*paca3$probf[8])/(paca3$Prediction[11]*paca3$probf[8]+(1-paca3$Prediction[11]))-paca3$Prediction[11], #Study 4 civil pro aca (Rep)
        (pcost3$Prediction[11]*pcost3$probf[8])/(pcost3$Prediction[11]*pcost3$probf[8]+(1-pcost3$Prediction[11]))-pcost3$Prediction[11], #Study 4 civil pro aca (Rep)
        (paca3$Prediction[6]*(1/paca3$conbf[14]))/(paca3$Prediction[6]*(1/paca3$conbf[14])+(1-paca3$Prediction[6]))-paca3$Prediction[6], #Study 4 uncivil con aca (Den)
        (pcost3$Prediction[6]*(1/pcost3$conbf[14]))/(pcost3$Prediction[6]*(1/pcost3$conbf[14])+(1-pcost3$Prediction[6]))-pcost3$Prediction[6], #Study 4 uncivil con cost (Dem)
        (paca3$Prediction[11]*paca3$probf[10])/(paca3$Prediction[11]*paca3$probf[10]+(1-paca3$Prediction[11]))-paca3$Prediction[11], #Study 4 uncivil pro aca (Rep)
        (pcost3$Prediction[11]*pcost3$probf[10])/(pcost3$Prediction[11]*pcost3$probf[10]+(1-pcost3$Prediction[11]))-pcost3$Prediction[11], #Study 4 uncivil pro aca (Rep)
        (paca4$Prediction[6]*(1/paca4$conbf[12]))/(paca4$Prediction[6]*(1/paca4$conbf[12])+(1-paca4$Prediction[6]))-paca4$Prediction[6], #Study 4 Univ civil con aca (Den)
        (pcost4$Prediction[6]*(1/pcost4$conbf[12]))/(pcost4$Prediction[6]*(1/pcost4$conbf[12])+(1-pcost4$Prediction[6]))-pcost4$Prediction[6], #Study 4 Univ civil con cost (Dem)
        (paca4$Prediction[11]*paca4$probf[8])/(paca4$Prediction[11]*paca4$probf[8]+(1-paca4$Prediction[11]))-paca4$Prediction[11], #Study 4 Univ civil pro aca (Rep)
        (pcost4$Prediction[11]*pcost4$probf[8])/(pcost4$Prediction[11]*pcost4$probf[8]+(1-pcost4$Prediction[11]))-pcost4$Prediction[11], #Study 4 Univ civil pro aca (Rep)
        (paca4$Prediction[6]*(1/paca4$conbf[14]))/(paca4$Prediction[6]*(1/paca4$conbf[14])+(1-paca4$Prediction[6]))-paca4$Prediction[6], #Study 4 Univ uncivil con aca (Den)
        (pcost4$Prediction[6]*(1/pcost4$conbf[14]))/(pcost4$Prediction[6]*(1/pcost4$conbf[14])+(1-pcost4$Prediction[6]))-pcost4$Prediction[6], #Study 4 Univ uncivil con cost (Dem)
        (paca4$Prediction[11]*paca4$probf[10])/(paca4$Prediction[11]*paca4$probf[10]+(1-paca4$Prediction[11]))-paca4$Prediction[11], #Study 4 Univ uncivil pro aca (Rep)
        (pcost4$Prediction[11]*pcost4$probf[10])/(pcost4$Prediction[11]*pcost4$probf[10]+(1-pcost4$Prediction[11]))-pcost4$Prediction[11] #Study 4 Univ uncivil pro aca (Rep)
    ),
    hostile=as.factor(c(rep(0,20),rep(1,12))),
    position=as.factor(c(0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1)),
    study=(c(rep(1,16),rep(4,16)))
    # new=c(rep(1,4),rep(0,10),rep(c(1,0),8)),
    # type=as.factor(c(rep(1,8),rep(2,2),rep(3,4),c(4,4,4,4),c(5,5,5,5),c(6,6,6,6),c(7,7,7,7)))
  )
  
  th<-theme(panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            legend.position = "none",
            legend.text=element_text(size=6),
            legend.key.size = unit(2, 'mm'),
            plot.title = element_text(size=8,hjust=0.5),
            axis.title = element_text(size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=6))
  
  
  lm(y~x,subset(results,hostile==0))%>%summary()
  lm(y~x,subset(results,hostile==1))%>%summary()
  
  
  ggplot(data=subset(results,hostile==0), aes(x=x,y=y))+
    geom_smooth(method='lm',se=TRUE,size=0.5,color="grey60", alpha = .2)+
    geom_point(size=2.5,aes(shape=position,color=position))+
    geom_hline(yintercept = 0, linetype="dashed",linewidth=0.2)+
    geom_vline(xintercept = 0, linetype="dashed",linewidth=0.2)+
    scale_y_continuous(breaks=c(-.2,-0.1,0,0.1,0.2),limits=c(-0.21,0.21))+
    scale_x_continuous(breaks=c(-.2,-0.1,0,0.1,0.2),limits=c(-0.21,0.21))+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    labs(x="Counterfactual Effects of Uncongenial Information",
         y = "Actual Effects of Uncongenial Information",
         title ="(A) Non-Hostile Conditions:\nStudy 1 + Study 4 (Ambivalent and Civil)")+
    scale_color_manual(name = c(""),
                       breaks=c("0","1"),
                       values=c("navy","red4"))+
    scale_shape_manual(name = c(""),
                       breaks=c("0","1"),
                       values=c(16,17))+
    guides(shape=guide_legend(title=NULL,reverse = TRUE),color=guide_legend(title=NULL,reverse = TRUE))+
    annotate("curve", x = c(-.14,.095), y = c(-0.10,0.04),
             xend = c(-.14,.095), yend = c(-0.125,0.05), color=c("navy","red4"),
             arrow = arrow(angle = 30, length = unit(1, "mm")),size=0.2,alpha=0.7, curvature =0.2)+
    annotate(geom="text",x =c(0.13,-.14,.12), y=c(0.15,-0.09,0.035),
             label=c("Slope = 1.1","Effects of Anti-ACA Info\non Democrats","Effects of Pro-ACA Info\non Republicans"),
             size=c(2.5,1.8,1.8),color=c("grey20","navy","red4"),vjust=c(0.5,0,1))+
    # geom_function(fun = function(x) x, linetype = "dashed", size = 0.5)+
    # geom_line(data = data.frame(x = c(-0.15,0.15),y = c(-0.15,0.15)),size=0.5,color="grey20",alpha=0.7)+
    theme_bw()+th
  ggsave("figs16a.png",width=3.25,height=3,dpi = 900)
  
  
  
  ggplot(data=subset(results,hostile==1), aes(x=x,y=y))+
    geom_smooth(method='lm',se=TRUE,size=0.5,color="grey60", alpha = .2)+
    geom_point(size=2.5,aes(shape=position,color=position))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.2)+
    geom_vline(xintercept = 0, linetype="dashed",size=0.2)+
    scale_y_continuous(breaks=c(-.2,-0.1,0,0.1,0.2),limits=c(-0.21,0.21))+
    scale_x_continuous(breaks=c(-.2,-0.1,0,0.1,0.2),limits=c(-0.21,0.21))+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    labs(x="Simulated Effects of Uncongenial Information",
         y = "Observed Effects of Uncongenial Information",
         title ="(B) Hostile Conditions:\nStudy 4 (Univalent or Uncivil)")+
    scale_color_manual(name = c(""),
                       breaks=c("0","1"),
                       values=c("navy","red4"))+
    scale_shape_manual(name = c(""),
                       breaks=c("0","1"),
                       values=c(16,17))+
    guides(shape=guide_legend(title=NULL,reverse = TRUE),color=guide_legend(title=NULL,reverse = TRUE))+
    annotate("curve", x = c(-.075,.085), y = c(.01,-.03),
             xend = c(-0.075,.085), yend = c(-0.01,-0.015), color=c("navy","red4"),
             arrow = arrow(angle = 30, length = unit(1, "mm")),size=0.2,alpha=0.7, curvature = .1)+
    annotate(geom="text",x =c(0.175,-.1,.1), y=c(0.05,0.015,-0.035),
             label=c("Slope = 0.5","Effects of Anti-ACA Information\non Democrats","Effects of Pro-ACA Information\non Republicans"),
             size=c(2.5,1.8,1.8),color=c("grey20","navy","red4"),vjust=c(0.5,0,1))+
    #geom_line(data = data.frame(x = c(-0.15,0.15),y = c(-0.15,0.15)),size=0.5,color="grey20",alpha=0.7)+
    theme_bw()+th
  ggsave("figs16b.png",width=3.25,height=3, dpi=900)
  
  
  #### Figures 17 and 18 ----
  
  
  
  support = c("Strongly\nOppose","Oppose", "Somewhat\nOppose","Neutral","Somewhat\nFavor","Favor","Strongly\nFavor")
  support = c("Strongly\nOppose","", "","Neutral","","","Strongly\nFavor")
  
  
  th<-  theme(
    panel.border = element_blank(),
    panel.grid.major.y = element_line(color = "grey90", linetype = "dotted", size = .2),
    panel.background = element_blank(),
    strip.background = element_rect(fill ="white",color = "white",size=1),
    axis.line = element_line(size = .3),
    plot.title = element_text(size = 6, hjust=0.5),
    axis.text = element_text(color = "black", size=6),
    axis.title.x = element_blank(),
    axis.title = element_text(color = "black", size=6),
    axis.ticks.x = element_line(linewidth = .3 ),
    axis.ticks.y = element_line(linewidth = .3 ),
    legend.text = element_text(size = 6),
    legend.key.size = unit (.4, 'cm'),
    legend.position = c(0.5, 0.85),
    #legend.key = element_rect(fill = "white"),
    legend.background = element_rect(fill="transparent"),
    legend.title = element_blank()
  ) 
  
  lm(w1aca~dem,aca)
  lm(aca0~dem,aca18)
  
  aca %>%
    filter(!is.na(w1aca))%>%
    filter(dem==0)%>%
    frq(w1aca1*6)%>%as.data.frame()%>%
    rbind(
      aca %>%
        filter(!is.na(w1aca))%>%
        filter(dem==1)%>%
        frq(w1aca1*6)%>%as.data.frame()
    )%>%
    filter(frq>0)%>%
    mutate(pid = c(rep("Rep",7),rep("Dem",7))%>%fct_relevel("Rep"),
           y = raw.prc*0.01)%>%
    ggplot(data = ., aes (x= val, y = y, color = pid, fill = pid))+
    geom_bar(stat="identity", position = position_dodge(width = 0.85), width = .75)+  
    scale_color_manual(values = c("red4", "#6495ED"))+
    scale_fill_manual(values = c("red4", "#6495ED"))+
    labs( title = "(A) Study 1 Pre-treatment (2016)", y = "Proprtions")+
    scale_x_continuous(breaks=0:6, labels = support)+
    scale_y_continuous(limits = c(0,.751), labels = scales::percent_format(accuracy = 1), expand = c(0, 0), breaks = 0.25*(0:3))+th
  ggsave("figs18a.pdf",width=3.25,height=2)
  
  
  aca18 %>%
    filter(!is.na(aca0))%>%
    filter(dem==0)%>%
    frq(aca0*6)%>%as.data.frame()%>%
    rbind(
      aca18 %>%
        filter(!is.na(aca0))%>%
        filter(dem==1)%>%
        frq(aca0*6)%>%as.data.frame()
    )%>%
    filter(frq>0)%>%
    mutate(pid = c(rep("Rep",7),rep("Dem",7))%>%fct_relevel("Rep"),
           y = raw.prc*0.01)%>%
    ggplot(data = ., aes (x= val, y = y, color = pid, fill = pid))+
    geom_bar(stat="identity", position = position_dodge(width = 0.85), width = .75)+  
    scale_color_manual(values = c("red4", "#6495ED"))+
    scale_fill_manual(values = c("red4", "#6495ED"))+
    labs( title = "(B) Study 2 Pre-treatment (2018)", y = "Proprtions")+
    scale_x_continuous(breaks=0:6, labels = support)+
    scale_y_continuous(limits = c(0,.751), labels = scales::percent_format(accuracy = 1), expand = c(0, 0), breaks = 0.25*(0:3))+th
  ggsave("figs18b.pdf",width=3.25,height=2)
  
  
  anes %>%
    filter(!is.na(V161114x)&V161114x>0)%>%
    filter(dem==0)%>%
    frq(7-V161114x, weights = V160101)%>%as.data.frame()%>%
    rbind(
      anes %>%
        filter(!is.na(V161114x)&V161114x>0)%>%
        filter(dem==1)%>%
        frq(7-V161114x, weights = V160101)%>%as.data.frame()  
    )%>%
    filter(frq>0)%>%
    mutate(pid = c(rep("Rep",7),rep("Dem",7))%>%fct_relevel("Rep"),
           y = raw.prc*0.01)%>%
    ggplot(data = ., aes (x= val, y = y, color = pid, fill = pid))+
    geom_bar(stat="identity", position = position_dodge(width = 0.85), width = .75)+  
    scale_color_manual(values = c("red4", "#6495ED"))+
    scale_fill_manual(values = c("red4", "#6495ED"))+
    labs( title = "(C) ANES (2016)", y = "Proprtions")+
    scale_x_continuous(breaks=0:6, labels = support)+
    scale_y_continuous(limits = c(0,.751), labels = scales::percent_format(accuracy = 1), expand = c(0, 0), breaks = 0.25*(0:3))+th
  ggsave("figs18c.pdf",width=3.25,height=2)
  
  
  anes18 %>%
    filter(!is.na(acaapprove)&acaapprove>0)%>%
    filter(dem==0)%>%
    frq(7-acaapprove, weights = weight_spss)%>%as.data.frame()%>%
    rbind(
      anes18 %>%
        filter(!is.na(acaapprove)&acaapprove>0)%>%
        filter(dem==1)%>%
        frq(7-acaapprove, weights = weight_spss)%>%as.data.frame()  
    )%>%
    filter(frq>0)%>%
    mutate(pid = c(rep("Rep",7),rep("Dem",7))%>%fct_relevel("Rep"),
           y = raw.prc*0.01)%>%
    ggplot(data = ., aes (x= val, y = y, color = pid, fill = pid))+
    geom_bar(stat="identity", position = position_dodge(width = 0.85), width = .75)+  
    scale_color_manual(values = c("red4", "#6495ED"))+
    scale_fill_manual(values = c("red4", "#6495ED"))+
    labs( title = "(D) ANES (2018)", y = "Proprtions")+
    scale_x_continuous(breaks=0:6, labels = support)+
    scale_y_continuous(limits = c(0,.751), labels = scales::percent_format(accuracy = 1), expand = c(0, 0), breaks = 0.25*(0:3))+th
  ggsave("figs18d.pdf",width=3.25,height=2)
  
  
  
  # CCES 2016
  
  lm(aca ~ dem, cc16)
  lm(aca ~ dem, cc18)
  
  cc16<-cc16%>%mutate(
    dem = case_when(
      pid7<4 ~ 1,
      pid7>4 & pid7<8 ~ 0,
    ),
    aca = CC16_351I-1,
    weight = commonweight
  )
  
  
  # Table S17-C and Table S18-E
  
  cc16 %>%
    filter(!is.na(aca))%>%
    filter(dem==0)%>%
    frq(aca, weights = weight)%>%as.data.frame()%>%
    rbind(
      cc16 %>%
        filter(!is.na(aca))%>%
        filter(dem==1)%>%
        frq(aca, weights = weight)%>%as.data.frame()
    )%>%
    filter(frq>0)%>%
    mutate(pid = c(rep("Rep",2),rep("Dem",2))%>%fct_relevel("Rep"),
           y = raw.prc*0.01)%>%
    ggplot(data = ., aes (x= val, y = y, color = pid, fill = pid))+
    geom_bar(stat="identity", position = position_dodge(width = 0.35), width = .3)+  
    scale_color_manual(values = c("red4", "#6495ED"))+
    scale_fill_manual(values = c("red4", "#6495ED"))+
    labs( title = "(E) CCES (2016)", y = "Proprtions")+
    # labs( title = "(C) CCES (2016)", y = "Proprtions")+ # alternative label used for table s17
    scale_x_continuous(breaks=0:1, labels = c("Repeal\nACA","Don't Repeal\nACA"))+
    scale_y_continuous(limits = c(0,1.01), labels = scales::percent_format(accuracy = 1), expand = c(0, 0), breaks = 0.25*(0:4))+th
  ggsave("figs18e.pdf",width=3.25,height=2)  
  
  
  # CCES 2018
  
  
  cc18<-cc18%>%mutate(
    dem = case_when(
      pid7<4 ~ 1,
      pid7>4 &  pid7 <8 ~ 0,
    ),
    aca = CC18_327c-1,
    weight = commonweight
  )
  
  # Table S17-D and Table S18-F
  
  cc18 %>%
    filter(!is.na(aca))%>%
    filter(dem==0)%>%
    frq(aca, weights = weight)%>%as.data.frame()%>%
    rbind(
      cc18 %>%
        filter(!is.na(aca))%>%
        filter(dem==1)%>%
        frq(aca, weights = weight)%>%as.data.frame()
    )%>%
    filter(frq>0)%>%
    mutate(pid = c(rep("Rep",2),rep("Dem",2))%>%fct_relevel("Rep"),
           y = raw.prc*0.01)%>%
    ggplot(data = ., aes (x= val, y = y, color = pid, fill = pid))+
    geom_bar(stat="identity", position = position_dodge(width = 0.35), width = .3)+  
    scale_color_manual(values = c("red4", "#6495ED"))+
    scale_fill_manual(values = c("red4", "#6495ED"))+
    labs( title = "(F) CCES (2018)", y = "Proprtions")+
    #labs( title = "(D) CCES (2018)", y = "Proprtions")+ # alternative label
    scale_x_continuous(breaks=0:1, labels = c("Repeal\nEntire ACA","Don't Repeal\nEntire ACA"))+
    scale_y_continuous(limits = c(0,1.01), labels = scales::percent_format(accuracy = 1), expand = c(0, 0), breaks = 0.25*(0:4))+th
  ggsave("figs18f.pdf",width=3.25,height=2)
  
  
  # Figure S19: comparison with other issues ----
  
  
  anes16dvs <- c(
    "V161114x", "V161194x", "V161195x", "V161196x",
    "V161204x", "V161213x", "V161214x", "V161226x",
    "V162147x", "V162150x", "V162176x", "V162295x"
  )
  
  
  anes16dv_e <- c(
    "V161114x_e", "V161194x_e", "V161195x_e", "V161196x_e",
    "V161204x_e", "V161213x_e", "V161214x_e", "V161226x_e",
    "V162147x_e", "V162150x_e", "V162176x_e", "V162295x_e"
  )
  
  anes <- anes %>%
    mutate(across(all_of(anes16dvs), ~ifelse(. >= 1 & . <= 7, ., NA)))
  
  for (var in anes16dvs) {
    anes[[paste0(var, "_e")]] <- ifelse(anes[[var]] == 1 | anes[[var]] == 7, 1, ifelse(anes[[var]] >= 2 & anes[[var]] <= 6, 0, NA))
  }
  
  # Define a function to get the appropriate weights
  get_weights <- function(dv) {
    if (dv %in% tail(anes16dvs, 4)) {
      return(anes$V160102)
    } else {
      return(anes$V160101)
    }
  }
  
  # Create the data frame with coefficients, lower bounds, and upper bounds
  anes16gaps <- data.frame(
    variable = anes16dvs,
    coefficient = sapply(anes16dvs, function(dv) {
      weights <- get_weights(dv)
      abs(coef(lm_robust(as.formula(paste(dv, "~ dem")), anes, weights = weights))[2])
    })/6,
    lb = sapply(anes16dvs, function(dv) {
      weights <- get_weights(dv)
      min(abs(confint(lm_robust(as.formula(paste(dv, "~ dem")), anes, weights = weights))[2, ]))
    })/6,
    ub = sapply(anes16dvs, function(dv) {
      weights <- get_weights(dv)
      max(abs(confint(lm_robust(as.formula(paste(dv, "~ dem")), anes, weights = weights))[2, ]))
    })/6)
  
  
  
  anes16gaps<-arrange(anes16gaps, coefficient)
  order_variables <- anes16gaps$variable
  
  capitalize_first <- function(s) {
    paste0(toupper(substring(s, 1, 1)), substring(s, 2))
  }
  
  anes.var<-lookfor(anes,"")
  
  
  anes16gaps<-anes16gaps%>%
    mutate(stat = c(rep("Distance between Dems and Reps (0-1)", 12)))%>%left_join(anes.var)%>%
    mutate(label = gsub("PRE: Summary: ", "", label),
           label = gsub("PRE: SUMMARY - ", "", label),
           label = gsub("POST: SUMMARY- ", "", label),
           label = gsub("Favor/oppose ", "", label),
           label = gsub("Favor or oppose ", "", label),
           label = sapply(label, capitalize_first),
           x = c(1:12),
           col = c(rep("b",11),"r")
    )
  
  anes16gaps$label[c(12)]<-"Obamacare"
  anes16gaps$label[c(5)]<-"Allow children brought illegally to stay"
  
  
  # ANES 2018
  
  anes18dvs <- c("integrity3", "integrity4", "integrity5", "birthright", "wall", "imigcit", "freetrade", "guncheck", "gunsar", "gunteach", "ice", "famsep", "acaapprove")
  
  anes18dv_e <- c("integrity3_e", "integrity4_e", "integrity5_e", "birthright_e", "wall_e", "imigcit_e", "freetrade_e", "guncheck_e", "gunsar_e", "gunteach_e", "ice_e", "famsep_e", "acaapprove_e")
  
  anes18 <- anes18 %>%
    mutate(across(all_of(anes18dvs), ~ (.-1) / (7-1)))
  
  for (var in anes18dvs) {
    anes18[[paste0(var, "_e")]] <- ifelse(anes18[[var]] == 0 | anes18[[var]] == 1, 1, ifelse(anes18[[var]] > 0 & anes18[[var]] < 1, 0, NA))
  }
  
  
  
  anes18gaps <- data.frame(
    variable = anes18dvs,
    coefficient = sapply(anes18dvs, function(dv) {
      abs(coef(lm_robust(as.formula(paste(dv, "~ dem")), anes18, weights = weight_spss))[2])
    }),
    lb = sapply(anes18dvs, function(dv) {
      min(abs(confint(lm_robust(as.formula(paste(dv, "~ dem")), anes18, weights = weight_spss))[2, ]))
    }),
    ub = sapply(anes18dvs, function(dv) {
      max(abs(confint(lm_robust(as.formula(paste(dv, "~ dem")), anes18, weights = weight_spss))[2, ]))
    }))
  
  
  
  anes18gaps<-arrange(anes18gaps[-13,], coefficient)%>%rbind(anes18gaps[13,])
  order_variables <- anes18gaps$variable
  
  capitalize_first <- function(s) {
    paste0(toupper(substring(s, 1, 1)), substring(s, 2))
  }
  
  
  
  anes18gaps<-anes18gaps%>%
    mutate(stat = c(rep("Distance between Dems and Reps (0-1)", 13)))%>%left_join(anes18.var)%>%
    mutate(label = gsub("In general, do you favor, oppose, or neither favor nor oppose ", "", label),
           label = gsub("Do you favor, oppose, or neither favor nor oppose ", "", label),
           label = gsub("\\?", "", label),
           label = gsub("Do you approve or disapprove of the practice of ", "", label),
           label = gsub("Do you approve or disapprove of ", "", label),
           x = c(1:13),
           col = c(rep("b",12),"r")
    )
  
  capitalize_first <- function(s) {
    paste0(toupper(substring(s, 1, 1)), substring(s, 2))
  }
  
  anes18gaps$label<-capitalize_first(anes18gaps$label)
  
  anes18gaps$label[1]<-"Free trade agreements"
  anes18gaps$label[2]<-"Background checks for gun purchases"
  anes18gaps$label[3]<-"Allow convicted felons to vote"
  anes18gaps$label[4]<-"Rquire photo ID to vote"
  anes18gaps$label[5]<-"Ban semi-automatic assault rifles"
  anes18gaps$label[6]<-"Allow registering to vote on Election Day"
  anes18gaps$label[7]<-"Unauthorized immigrants to qualify for citizenship"
  anes18gaps$label[8]<-"Separate children from parents crossing border"
  anes18gaps$label[9]<-"End birthright citizenship"
  anes18gaps$label[10]<-"Allow teachers to carry guns at school"
  anes18gaps$label[11]<-"Approve Immigration and Customs Enforcement (ICE)"
  anes18gaps$label[12]<-"Build wall with Mexico"
  anes18gaps$label[13]<-"Obamacare"
  
  
  anes.other<-rbind(anes16gaps,anes18gaps)%>%
    mutate(x = 1:25,
           year = ifelse(1:25 <= 12, " (A) ANES 2016", "(B) ANES 2018")
    )
  
  
  
  
  
  th<-theme(panel.grid.major.y = element_line(color = "grey70", linetype = "solid", size = .3),
            panel.grid.major.x = element_line(color = "grey70", linetype = "dotted", size = .3),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            strip.text = element_text(size = 7),
            legend.position = "none",
            legend.text=element_text(size=6),
            legend.key.size = unit(1.5, 'mm'),
            legend.background = element_rect(fill="transparent"),
            plot.title = element_blank(),
            axis.title.y = element_blank(),
            axis.title.x = element_text(color = "black", size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=6),
            strip.background = element_rect(fill ="white",color = "white",size=1))
  
  
  
  
  library(ggh4x)
  
  ggplot(anes.other, aes(y = coefficient, x = x, color = col))+
    geom_point()+
    geom_linerange(ymin = anes.other$lb, ymax = anes.other$ub)+
    labs(title = "", y="Dems vs. Reps Distance (1 = Max Polarization)")+
    scale_color_manual(values = c("black","red4"))+
    scale_y_continuous(breaks = 0:3*0.25, limits = c(0, .75))+
    scale_x_continuous(breaks = 1:25, labels = anes.other$label)+theme_bw()+th+
    coord_flip()+
    facet_grid2(year ~ ., scales = "free_y", space = "free_y")+
    theme(strip.background = element_rect(fill ="white",color = "white",size=1))+th
  ggsave("figs19.pdf",width=6.3,height=4)
  
  
  
  
  # Figure S20: Partisan Polarization over the ACA vs. Other Issues (CCES) ----
  
  
  cc16dvs <- c("CC16_351I","CC16_330a", "CC16_330b", "CC16_330d", "CC16_330e", 
               "CC16_331_1", "CC16_331_2", "CC16_331_3", "CC16_331_4", 
               "CC16_331_5", "CC16_331_6", "CC16_331_7", "CC16_331_8", 
               "CC16_331_9", "CC16_332a", "CC16_332b", "CC16_332c", 
               "CC16_332d", "CC16_332e", "CC16_332f", "CC16_333a", 
               "CC16_333b", "CC16_333c", "CC16_333d", "CC16_334a", 
               "CC16_334b", "CC16_334c", "CC16_334d", "CC16_335")
  
  
  # Function to get the group identifier from the variable name
  get_group <- function(variable) {
    substr(variable, 6, 8)
  }
  
  cc16gaps <- data.frame(variable = cc16dvs, 
                         coefficient =  sapply(cc16dvs, function(dv) {
                           abs(coef(lm_robust(as.formula(paste(dv, "~ dem")), cc16, weights = weight))[2])
                         }), 
                         lb =  sapply(cc16dvs, function(dv) {
                           min(abs(confint(lm_robust(as.formula(paste(dv, "~ dem")), cc16, weights = weight))[2,]))
                         }), 
                         ub =  sapply(cc16dvs, function(dv) {
                           max(abs(confint(lm_robust(as.formula(paste(dv, "~ dem")), cc16, weights = weight))[2,]))
                         }), 
                         group = sapply(cc16dvs, get_group))
  
  # Sort within each group by the coefficient size and select top 2
  cc16gaps.sorted <- do.call(rbind, lapply(split(cc16gaps, cc16gaps$group), function(df) {
    cc16gaps.sorted <- df[order(-df$coefficient), ]
    head(cc16gaps.sorted, 2)
  }))%>%
    left_join(dplyr::select(cc16.var, variable, label))
  
  cc16gaps.sorted$label[5]<-"Abortion - Allow employers to decline coverage of abortions in insurance"
  cc16gaps.sorted$label[6]<-"Abortion - Prohibit the expenditure of federal funds for abortion"
  cc16gaps.sorted$label[7]<-"Environment - Strengthen Clean Air Water Act act even if it costs jobs"
  cc16gaps.sorted$label[8]<-"Environment - Empower EPA to regulate CO2 Emission"
  cc16gaps.sorted$label[9]<-"Crime - No mandatory minimum sentences for non-violent drug"
  cc16gaps.sorted$label[10]<-"Crime - Increase police by 10 percent, even if funds for other services"
  cc16gaps.sorted$label[11]<-"Legalize gay marriage"
  cc16gaps.sorted$label[12]<-"Repeal Obamacare"
  
  
  cc16gaps.sorted<-arrange(cc16gaps.sorted, coefficient)%>%mutate(x=1:12, col = c(rep("b",11),"r"))
  
  
  cc18dvs <- c("CC18_320a", "CC18_320c", "CC18_320d", "CC18_321a", "CC18_321b", "CC18_321c", 
               "CC18_321d", "CC18_321e", "CC18_321f", "CC18_322a", "CC18_322b", 
               "CC18_322c_new", "CC18_322d_new", "CC18_322c", "CC18_322f", 
               "CC18_325a", "CC18_325b", "CC18_325c", "CC18_325d", 
               "CC18_325e_new", "CC18_325f_new", "CC18_327c")
  
  
  cc18gaps <- data.frame(variable = cc18dvs, 
                         coefficient =  sapply(cc18dvs, function(dv) {
                           abs(coef(lm_robust(as.formula(paste(dv, "~ dem")), cc18, weights = weight))[2])
                         }), 
                         lb =  sapply(cc18dvs, function(dv) {
                           min(abs(confint(lm_robust(as.formula(paste(dv, "~ dem")), cc18, weights = weight))[2,]))
                         }), 
                         ub =  sapply(cc18dvs, function(dv) {
                           max(abs(confint(lm_robust(as.formula(paste(dv, "~ dem")), cc18, weights = weight))[2,]))
                         }), 
                         group = sapply(cc18dvs, get_group))
  
  # Sort within each group by the coefficient size and select top 2
  cc18gaps.sorted <- do.call(rbind, lapply(split(cc18gaps, cc18gaps$group), function(df) {
    cc18gaps.sorted <- df[order(-df$coefficient), ]
    head(cc18gaps.sorted, 2)}))%>%
    left_join(dplyr::select(cc18.var, variable, label))%>%
    mutate(label = gsub("--", "-", label))
  
  cc18gaps.sorted$label[2]<-"Gun Control - Make it easier for people to obtain concealed-carry permit"
  cc18gaps.sorted$label[3]<-"Abortion - Prohibit the expenditure of federal funds for abortion"
  cc18gaps.sorted$label[4]<-"Abortion - Allow employers to decline coverage of abortions in insurance"
  cc18gaps.sorted$label[5]<-"Immigration - More spending on border security, building \"the wall\""
  cc18gaps.sorted$label[6]<-"Immigration - Local police to report anyone identified as illegal immigrant"
  cc18gaps.sorted$label[8]<-"Taxes - Reduce the income tax for households earning more than $500K"
  cc18gaps.sorted$label[9]<-"Repeal the entire Obamacare"
  
  cc18gaps.sorted<-cc18gaps.sorted%>%filter(variable!="CC18_327c")%>%arrange(coefficient)%>%
    rbind(cc18gaps.sorted%>%filter(variable =="CC18_327c"))%>%mutate(x=1:9, col = c(rep("b",8),"r"))
  
  
  
  
  th<-theme(panel.grid.major.y = element_line(color = "grey70", linetype = "solid", size = .3),
            panel.grid.major.x = element_line(color = "grey70", linetype = "dotted", size = .3),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            strip.text = element_text(size = 7),
            legend.position = "none",
            legend.text=element_text(size=6),
            legend.key.size = unit(1.5, 'mm'),
            legend.background = element_rect(fill="transparent"),
            plot.title = element_blank(),
            axis.title.y = element_blank(),
            axis.title.x = element_text(color = "black", size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=6),
            strip.background = element_rect(fill ="white",color = "white",size=1))
  
  
  cc.other<- rbind (cc16gaps.sorted,cc18gaps.sorted)%>%
    mutate( x = 1:21,
            year = ifelse(x <=12, "(A) CCES 2016", "(B) CCES 2018"))
  
  
  
  
  ggplot(cc.other, aes(y = coefficient, x = x, color = col))+
    geom_point()+
    geom_linerange(ymin = cc.other$lb, ymax = cc.other$ub)+
    labs(title = "", y="Dems vs. Reps Distance (1 = Max Polarization)")+
    scale_color_manual(values = c("black","red4"))+
    scale_y_continuous(breaks = 1:3*0.25, limits = c(.2, .75))+
    scale_x_continuous(breaks = 1:21, labels = cc.other$label)+theme_bw()+th+
    coord_flip()+
    facet_grid2(year ~ ., scales = "free_y", space = "free_y")+
    theme(strip.background = element_rect(fill ="white",color = "white",size=1))+th
  ggsave("figs20.pdf",width=6.3,height=3.5)
  
  
  # Figure S21: Perceived Importance Healthcare vs. Other Issues (CCES 2016) ----
  
  
  cc16dvs <- c("CC16_301a", "CC16_301b", "CC16_301c", "CC16_301d", "CC16_301e", "CC16_301f", "CC16_301g", "CC16_301h", "CC16_301i", "CC16_301j", "CC16_301k", "CC16_301l", "CC16_301m", "CC16_301n", "CC16_301o")
  
  frq(cc16[cc16dvs])
  
  cc16importance <- data.frame(variable = cc16dvs, 
                               coefficient =  sapply(cc16dvs, function(dv) {
                                 abs(coef(lm_robust(as.formula(paste(dv, "==1 ~ 1")), cc16, weights = weight))[1])
                               }), 
                               lb =  sapply(cc16dvs, function(dv) {
                                 min(abs(confint(lm_robust(as.formula(paste(dv, "==1 ~ 1")), cc16, weights = weight))[1,]))
                               }), 
                               ub =  sapply(cc16dvs, function(dv) {
                                 max(abs(confint(lm_robust(as.formula(paste(dv, "==1 ~ 1")), cc16, weights = weight))[1,]))
                               }))
  
  # Sort within each group by the coefficient size and select top 2
  cc16importance <- cc16importance%>%
    left_join(dplyr::select(cc16.var, variable, label))%>%
    mutate(label = gsub("Most Important Problem - ", "", label))
  
  cc16importance.sorted<-cc16importance[-13,]%>%arrange(coefficient)%>%
    rbind(cc16importance[13,])%>%
    mutate(x = 1:15, col = c(rep("b",14),"r") )
  
  
  
  ggplot(cc16importance.sorted, aes(y = coefficient, x = x, color = col))+
    geom_point()+
    geom_linerange(ymin = cc16importance.sorted$lb, ymax = cc16importance.sorted$ub)+
    coord_flip()+
    labs(y = "Proportions indicationg \"very high importance\"", title = "", x="")+
    scale_color_manual(values = c("black","red4"))+
    scale_y_continuous(breaks = (2:6)*0.1, limits = c(.15, .65))+
    scale_x_continuous(breaks = 1:15, labels = (cc16importance.sorted$label))+theme_bw()+th
  ggsave("figs21.pdf",width=5,height=3)
  
  
  
  
  # Figure S22: Trends in Support for the ACA (2012-2020) ----
  
  
  anes.trend<-rbind(
    anes12%>%dplyr::select(aca,dem,weights,year),
    anes%>%dplyr::select(aca,dem,weights,year),
    anes18%>%dplyr::select(aca,dem,weights,year),
    anes20%>%dplyr::select(aca,dem,weights,year)
  )
  
  th<-theme(panel.grid.major.y = element_line(color = "grey70", linetype = "dotted", size = .3),
            panel.grid.major.x = element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            strip.text = element_text(size = 7),
            legend.position = c(.3,.5),
            legend.text=element_text(size=6),
            legend.key.width = unit(13, 'mm'),
            legend.background = element_rect(fill="transparent"),
            plot.title = element_text(color = "black", size=7, hjust = .5),
            axis.title.y = element_text(color = "black", size=7),
            axis.title.x = element_blank(),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=6),
            strip.background = element_rect(fill ="white",color = "white",size=1))
  
  
  anes.trend$rep <- 1- anes.trend$dem
  
  anes.trend%>%
    filter(!is.na(rep))%>%
    group_by(year, rep)%>%
    do(tidy(lm_robust(aca~1, data = .)))%>%
    filter(term == "(Intercept)")%>%
    ggplot(aes(x = year, y = estimate, color = factor(rep), fill = factor(rep), shape = factor(rep), linetype = factor(rep)), data = .)+
    geom_line()+
    scale_y_continuous (breaks = 0:4*.25, limits = c(0,1))+
    geom_point(size = 2)+
    geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, colour = NA)+
    scale_fill_manual(name = c(""),
                      breaks=c("0", "1"),
                      labels = c("Dem","Rep"),
                      values=c("navy","red4"))+
    scale_color_manual(name = c(""),
                       breaks=c("0", "1"),
                       labels = c("Dem","Rep"),
                       values=c("navy","red4"))+
    scale_linetype_manual(name = c(""),
                          breaks=c("0", "1"),
                          labels = c("Dem","Rep"),
                          values=c("solid","dashed"))+theme_bw()+th+
    scale_shape_manual(name = c(""),
                       breaks=c("0", "1"),
                       labels = c("Dem","Rep"),
                       values=c(16, 17))+
    labs(y = "1 = Favor the ACA a great deal", title = "(A) ACA Support Trends in ANES")
  ggsave("figs22a.png",width=3.25,height=3, dpi = 1200)
  
  
  cc.trend<-rbind(
    cc12%>%dplyr::select(aca,dem,weight,year),
    cc13%>%dplyr::select(aca,dem,weight,year),
    cc14%>%dplyr::select(aca,dem,weight,year),
    cc15%>%dplyr::select(aca,dem,weight,year),
    cc16%>%dplyr::select(aca,dem,weight,year),
    cc17%>%dplyr::select(aca,dem,weight,year),
    cc18%>%dplyr::select(aca,dem,weight,year),
    cc19%>%dplyr::select(aca,dem,weight,year),
    cc20%>%dplyr::select(aca,dem,weight,year)
  )
  
  cc.trend$rep = 1- cc.trend$dem
  
  
  cc.trend%>%
    filter(!is.na(rep))%>%
    group_by(year, rep)%>%
    do(tidy(lm_robust(aca~1, data = .)))%>%
    filter(term == "(Intercept)")%>%
    ggplot(aes(x = year, y = estimate, color = factor(rep), fill = factor(rep), shape = factor(rep), linetype = factor(rep)), data = .)+
    geom_line()+
    scale_y_continuous (breaks = 0:4*.25, limits = c(0,1))+
    geom_point(size = 2)+
    geom_ribbon(aes(ymin = conf.low, ymax = conf.high), alpha = .2, colour = NA)+
    scale_fill_manual(name = c(""),
                      breaks=c("0", "1"),
                      labels = c("Dem","Rep"),
                      values=c("navy","red4"))+
    scale_color_manual(name = c(""),
                       breaks=c("0", "1"),
                       labels = c("Dem","Rep"),
                       values=c("navy","red4"))+
    scale_linetype_manual(name = c(""),
                          breaks=c("0", "1"),
                          labels = c("Dem","Rep"),
                          values=c("solid","dashed"))+theme_bw()+th+
    scale_shape_manual(name = c(""),
                       breaks=c("0", "1"),
                       labels = c("Dem","Rep"),
                       values=c(16, 17))+
    labs(y = "Against Repealing ACA", title = "(B) ACA Support Trends in CCES")
  ggsave("figs22b.png",width=3.25,height=3, dpi = 1200)
  
  
  # Figure S23: Partisan Polarization on the Economy (ANES 2016) ----
  
  th<-  theme(
    panel.border = element_blank(),
    panel.grid.major.y = element_line(color = "grey90", linetype = "dotted", size = .2),
    panel.background = element_blank(),
    strip.background = element_rect(fill ="white",color = "white",size=1),
    axis.line = element_line(size = .3),
    plot.title = element_text(size = 6, hjust=0.5),
    axis.text = element_text(color = "black", size=6),
    axis.title.x = element_blank(),
    axis.title = element_text(color = "black", size=6),
    axis.ticks.x = element_line(linewidth = .3 ),
    axis.ticks.y = element_line(linewidth = .3 ),
    legend.text = element_text(size = 6),
    legend.key.size = unit (.4, 'cm'),
    legend.position = c(0.5, 0.85),
    #legend.key = element_rect(fill = "white"),
    legend.background = element_rect(fill="transparent"),
    legend.title = element_blank()
  ) 
  
  
  anes<-anes %>%
    mutate(econ = case_when ( V161144 == 1 ~ 2, V161144 ==2 ~ 0, V161144 >=3 ~ 1),
           econp = case_when ( V161083x > 0 ~ 4-V161083x))
  
  
  
  anes %>%
    filter(!is.na(econp))%>%
    filter(dem==0)%>%
    frq(econp, weights = weights)%>%as.data.frame()%>%
    rbind(
      anes %>%
        filter(!is.na(econp))%>%
        filter(dem==1)%>%
        frq(econp, weights = weights)%>%as.data.frame())%>%
    filter(frq>0)%>%
    mutate(pid = c(rep("Republicans",4),rep("Democrats",4))%>%fct_relevel("Republicans"),
           y = raw.prc*0.01)%>%
    ggplot(data = ., aes (x= val, y = y, color = pid, fill = pid))+
    geom_bar(stat="identity", position = position_dodge(width = 0.35), width = .3)+  
    scale_color_manual(values = c("red4", "#6495ED"))+
    scale_fill_manual(values = c("red4", "#6495ED"))+
    labs( title = "(A) President's Handing of the Economy", y = "Proprtions")+
    scale_x_continuous(breaks=0:3, labels = c("Disapprove\nStrongly", "Disapprove", "Approve", "Approve\nStrongly"))+
    scale_y_continuous(limits = c(0,1.01), labels = scales::percent_format(accuracy = 1), expand = c(0, 0), breaks = 0.25*(0:4))+th
  ggsave("figs23a.pdf",width=3.25,height=2)
  
  
  anes %>%
    filter(!is.na(econ))%>%
    filter(dem==0)%>%
    frq(econ, weights = weights)%>%as.data.frame()%>%
    rbind(
      anes %>%
        filter(!is.na(econ))%>%
        filter(dem==1)%>%
        frq(econ, weights = weights)%>%as.data.frame())%>%
    filter(frq>0)%>%
    mutate(pid = c(rep("Republicans",3),rep("Democrats",3))%>%fct_relevel("Republicans"),
           y = raw.prc*0.01)%>%
    ggplot(data = ., aes (x= val, y = y, color = pid, fill = pid))+
    geom_bar(stat="identity", position = position_dodge(width = 0.35), width = .3)+  
    scale_color_manual(values = c("red4", "#6495ED"))+
    scale_fill_manual(values = c("red4", "#6495ED"))+
    labs( title = "(B) Which Party Handels the Economy Better?", y = "Proprtions")+
    scale_x_continuous(breaks=0:2, labels = c("Republican\nParty", "Not Much\nDifference", "Democratic\nParty"))+
    scale_y_continuous(limits = c(0,1.01), labels = scales::percent_format(accuracy = 1), expand = c(0, 0), breaks = 0.25*(0:4))+th
  ggsave("figs23b.pdf",width=3.25,height=2)
  
  
  
  
  # Figure S24 ----
  
  
  
  
  m1<-tidy(lm_robust(econ~c+econ0+pid,data=subset(econ),se_type="HC2"))
  m2<-tidy(lm_robust(econ~c+econ0+pid,data=subset(econ,dem==1),se_type="HC2"))
  m3<-tidy(lm_robust(econ~c+econ0+pid,data=subset(econ,dem==0),se_type="HC2"))
  het1<-tidy(lm_robust(econ~c*dem+econ0*dem+pid*dem,data=subset(econ),se_type="HC2"))
  econest<-bind_rows(all=m1[2:5,],dem=m2[2:5,],rep=m3[2:5,],.id="pid")
  hecon<-het1[9:12,]
  
  
  th<-theme(panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            axis.title.x=element_blank(),
            legend.position = c(0.25, 0.2),
            legend.text=element_text(size=6),
            legend.key.size = unit(3, 'mm'),
            plot.title = element_text(size=8,hjust=0.5),
            axis.title.y= element_text(size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=6))
  
  
  fig5.1<-ggplot(data=subset(econest,(term=="c1"|term=="c2")&pid!="all"), aes(x=term, y=estimate, shape=pid,color=pid))+ 
    geom_point(aes(),position=position_dodge(0.4),size=2)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c("black","navy","red4"))+  
    theme_bw()+
    scale_x_discrete(breaks=c("c1","c2"),
                     labels=c("GDP\nWeak","GDP\nStrong"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.4), size=0.4)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    labs(title="(A) Effect of GDP Evidence on \n Preference for the Democratic Party",x="", y = "Difference from Control")+
    scale_y_continuous(breaks=c(-0.15,-0.1,-0.05,0,0.05,0.1,0.15),limits=c(-0.15,0.15))+
    th
  
  
  fig5.2<-ggplot(data=subset(econest,(term=="c3"|term=="c4")&pid!="all"), aes(x=term, y=estimate, shape=pid,color=pid))+ 
    geom_point(aes(),position=position_dodge(0.4),size=2)+ 
    scale_shape_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c(15,16, 17))+
    scale_color_manual(name = c(""),
                       breaks=c("all","dem","rep"),
                       labels = c("All","Democrats", "Republicans"),
                       values=c("black","navy","red4"))+  
    theme_bw()+
    scale_x_discrete(breaks=c("c3","c4"),
                     labels=c("Equality\nWeak","Equality\nStrong"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.4), size=0.4)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    labs(title="(B) Effect of Equality Evidence on \n Preference for the Democratic Party",x="", y = "Difference from Control")+
    scale_y_continuous(breaks=c(-0.15,-0.1,-0.05,0,0.05,0.1,0.15),limits=c(-0.15,0.15))+
    th
  
  fig5.1+fig5.2
  ggsave("figs24ab.pdf",width=6.4,height=3)
  
  
  
  fig5.3<-ggplot(data=subset(hecon,term=="c1:dem"|term=="c2:dem"), aes(x=term, y=estimate))+ 
    geom_point(aes(),shape=1,stroke =.4,size=2)+ 
    theme_bw()+
    scale_x_discrete(breaks=c("c1:dem","c2:dem"),
                     labels=c("GDP\nWeak","GDP\nStrong"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.4), size=0.4)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    labs(title="(C) Partisan Difference in \n Effect of GDP Evidence",x="", y = "Difference-in-Differences (Dem - Rep)")+
    annotate(geom="text",x ="c1:dem", y=c(-0.15,0.15),
             label=c("Negative Diff = Narrowing Partisan Gap",
                     "Positive Diff = Widening Partisan Gap"),
             size=1.8,hjust=0.15)+ 
    scale_y_continuous(breaks=c(-0.15,-0.1,-0.05,0,0.05,0.1,0.15),limits=c(-0.15,0.15))+
    th
  
  fig5.4<-ggplot(data=subset(hecon,term=="c3:dem"|term=="c4:dem"), aes(x=term, y=estimate))+ 
    geom_point(aes(),shape=1,stroke =.4,size=2)+ 
    theme_bw()+
    scale_x_discrete(breaks=c("c3:dem","c4:dem"),
                     labels=c("Equality\nWeak","Equality\nStrong"))+
    theme(text=element_text(size=9))+
    geom_hline(yintercept = 0, linetype="dashed",size=0.4)+
    geom_linerange(aes(ymin = conf.low, ymax = conf.high),position=position_dodge(0.4), size=0.4)+
    guides(shape=guide_legend(title=NULL),color=guide_legend(title=NULL))+
    labs(title="(D) Partisan Difference in \n Effect of Equality Evidence",x="", y = "Difference-in-Differences (Dem - Rep)")+
    annotate(geom="text",x ="c3:dem", y=c(-0.15,0.15),
             label=c("Negative Diff = Narrowing Partisan Gap",
                     "Positive Diff = Widening Partisan Gap"),
             size=1.8,hjust=0.15)+ 
    scale_y_continuous(breaks=c(-0.15,-0.1,-0.05,0,0.05,0.1,0.15),limits=c(-0.15,0.15))+
    th
  
  fig5.3+fig5.4
  ggsave("figs24cd.pdf",width=6.4,height=3)
  
  # Figure S25 ----
  
  
  
  time_gap<-as.numeric(ymd(econ$start2)-ymd(econ$StartDate))
  summary(time_gap)
  sum(!is.na(time_gap))
  
  econ.lr<-rbind(
    econ%>%
      filter(!is.na(dem)&!is.na(w2econ))%>%
      group_by(dem)%>%
      do(tidy(lm_robust(econ ~ c2 + econ0+pid, data = .)))%>%
      filter(term=="c21")%>%mutate(t = 1),
    econ%>%
      filter(!is.na(dem)&!is.na(w2econ))%>%
      group_by(dem)%>%
      do(tidy(lm_robust(w2econ ~ c2 + econ0+pid, data = .)))%>%
      filter(term=="c21")%>%mutate(t = 2))%>%
    mutate(dem = factor(dem))
  
  
  econ.lr.recall1<-rbind(
    econ%>%
      filter(!is.na(dem)&!is.na(w2recall1))%>%
      group_by(dem)%>%
      do(tidy(lm_robust(recall1 ~ 1, data = .)))%>%
      mutate(t = 1),
    econ%>%
      filter(!is.na(dem)&!is.na(w2recall1))%>%
      group_by(dem)%>%
      do(tidy(lm_robust(w2recall1 ~1, data = .)))%>%
      mutate(t = 2))%>%
    mutate(dem = factor(dem))
  
  
  econ.lr.recall2<-rbind(
    econ%>%
      filter(!is.na(dem)&!is.na(w2recall2))%>%
      group_by(dem)%>%
      do(tidy(lm_robust(recall2 ~ 1, data = .)))%>%
      mutate(t = 1),
    econ%>%
      filter(!is.na(dem)&!is.na(w2recall2))%>%
      group_by(dem)%>%
      do(tidy(lm_robust(w2recall2 ~1, data = .)))%>%
      mutate(t = 2))%>%
    mutate(dem = factor(dem))
  
  th<-theme(panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            panel.border=element_rect(colour="black"),
            axis.title.x=element_blank(),
            legend.position = c(0.3, 0.85),
            legend.background = element_rect(fill="transparent"),
            legend.text=element_text(size=7),
            legend.key.size = unit(3, 'mm'),
            legend.key.width = unit(9, 'mm'),
            plot.title = element_text(size=8,hjust=0.5),
            axis.title.y= element_text(size=7),
            axis.text.x = element_text(color = "black", size=6),
            axis.text.y = element_text(color = "black", size=7))
  
  
  ggplot(data=econ.lr, aes(x=t, y=estimate, color=dem, fill = dem,shape = dem,linetype = dem))+ 
    geom_point(aes(),size=2,alpha=1)+ 
    geom_line(aes(),size=0.3)+geom_ribbon(aes(ymin=conf.low, ymax=conf.high), alpha = 0.2, colour = NA)+
    scale_shape_manual(name = c(""),
                       breaks=c("0","1"),
                       labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                       values=c(17,16))+
    scale_linetype_manual(name = c(""),
                          breaks=c("0","1"),
                          labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                          values=c(2,1))+
    scale_fill_manual(name = c(""),
                      breaks=c("0","1"),
                      labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                      values=c("red4","navy"))+
    scale_color_manual(name = c(""),
                       breaks=c("0","1"),
                       labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                       values=c("red4","navy"))+
    theme_bw()+
    scale_x_continuous(breaks=c(1,2),
                       labels=c("Immediate", "10 days"))+
    geom_hline(yintercept = 0, linetype="dotted",size=0.5)+
    labs(title="(A) Treatment Effects",x="", y = "Treatment Effects (Pooled)")+
    ylim(-0.01,0.15)+
    guides(fill=guide_legend(title=NULL),color=guide_legend(title=NULL),linetype=guide_legend(title=NULL),shape=guide_legend(title=NULL))+
    th+ theme(legend.position = c(0.5, 0.85))
  ggsave("figs25a.png",width=2.15,height=3, dpi = 1200)
  
  
  
  
  ggplot(data=econ.lr.recall1, aes(x=t, y=estimate, color=dem, fill = dem,shape = dem,linetype = dem))+ 
    geom_point(aes(),size=2,alpha=1)+ 
    geom_line(aes(),size=0.3)+geom_ribbon(aes(ymin=conf.low, ymax=conf.high), alpha = 0.2, colour = NA)+
    scale_shape_manual(name = c(""),
                       breaks=c("0","1"),
                       labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                       values=c(17,16))+
    scale_linetype_manual(name = c(""),
                          breaks=c("0","1"),
                          labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                          values=c(2,1))+
    scale_fill_manual(name = c(""),
                      breaks=c("0","1"),
                      labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                      values=c("red4","navy"))+
    scale_color_manual(name = c(""),
                       breaks=c("0","1"),
                       labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                       values=c("red4","navy"))+
    theme_bw()+
    scale_x_continuous(breaks=c(1,2),
                       labels=c("Immediate", "10 days"))+
    geom_hline(yintercept = 0, linetype="dotted",size=0.5)+
    labs(title="(B) Message Recall",x="", y = "Recall Rate")+
    ylim(-0.01,1.01)+
    guides(fill=guide_legend(title=NULL),color=guide_legend(title=NULL),linetype=guide_legend(title=NULL),shape=guide_legend(title=NULL))+
    th+ theme(legend.position = c(0.5, 0.25))
  ggsave("figs25b.png",width=2.15,height=3, dpi = 1200)
  
  
  
  ggplot(data=econ.lr.recall2, aes(x=t, y=estimate, color=dem, fill = dem,shape = dem,linetype = dem))+ 
    geom_point(aes(),size=2,alpha=1)+ 
    geom_line(aes(),size=0.3)+geom_ribbon(aes(ymin=conf.low, ymax=conf.high), alpha = 0.2, colour = NA)+
    scale_shape_manual(name = c(""),
                       breaks=c("0","1"),
                       labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                       values=c(17,16))+
    scale_linetype_manual(name = c(""),
                          breaks=c("0","1"),
                          labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                          values=c(2,1))+
    scale_fill_manual(name = c(""),
                      breaks=c("0","1"),
                      labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                      values=c("red4","navy"))+
    scale_color_manual(name = c(""),
                       breaks=c("0","1"),
                       labels = c("Rep (Uncongenial)", "Dem (Congenial)"),
                       values=c("red4","navy"))+
    theme_bw()+
    scale_x_continuous(breaks=c(1,2),
                       labels=c("Immediate", "10 days"))+
    geom_hline(yintercept = 0, linetype="dotted",size=0.5)+
    labs(title="(C) Chart Recall",x="", y = "Recall Rate")+
    ylim(-0.01,1.01)+
    guides(fill=guide_legend(title=NULL),color=guide_legend(title=NULL),linetype=guide_legend(title=NULL),shape=guide_legend(title=NULL))+
    th+ theme(legend.position = c(0.5, 0.25))
  ggsave("figs25c.png",width=2.15,height=3, dpi = 1200)
  
  
  # Figure S26 ----
  
  
  
  
  e<-econ%>%filter(!is.na(w2econ)&!is.na(dem))
  
  e_r <- e %>% filter(dem == 0)
  e_d <- e %>% filter(dem == 1)
  
  
  
  
  # Define a function to fit models and calculate the ratio
  calculate_ratio <- function(data) {
    model_econ <- lm_robust(econ ~ c2 + econ0 + pid, data = data)
    model_w2econ <- lm_robust(w2econ ~ c2 + econ0 + pid, data = data)
    
    coef_econ <- tidy(model_econ) %>% filter(term == "c21") %>% pull(estimate)
    coef_w2econ <- tidy(model_w2econ) %>% filter(term == "c21") %>% pull(estimate)
    
    ratio <- coef_w2econ / coef_econ
    return(ratio)
  }
  
  # Apply the function to both subgroups
  ratio_r <- calculate_ratio(e_r)
  ratio_d <- calculate_ratio(e_d)
  
  # Calculate the difference between the ratios
  ratio_diff <- ratio_d - ratio_r
  
  # Bootstrap 
  set.seed(123)
  boot_data_r <- bootstraps(e_r, times = 1000)
  boot_data_d <- bootstraps(e_d, times = 1000)
  
  # Function to calculate the ratio for bootstrapped samples
  boot_ratio <- function(split) {
    data <- analysis(split)
    calculate_ratio(data)
  }
  
  # Calculate bootstrap ratios
  boot_ratios_r <- boot_data_r %>% mutate(ratio = map_dbl(splits, boot_ratio))
  boot_ratios_d <- boot_data_d %>% mutate(ratio = map_dbl(splits, boot_ratio))
  
  # Calculate bootstrap differences
  boot_diffs <- boot_ratios_d %>% mutate(ratio_diff = ratio - boot_ratios_r$ratio)
  
  # Summarize results
  boot_summary <- boot_diffs %>%
    summarise(mean_ratio_diff = mean(ratio_diff),
              lower_ci = quantile(ratio_diff, 0.025),
              upper_ci = quantile(ratio_diff, 0.975))
  
  print(boot_summary)
  
  
  ratio.df <- data.frame(
    estimate = c(econ.lr$estimate[3]/econ.lr$estimate[1], econ.lr$estimate[4]/econ.lr$estimate[2], econ.lr$estimate[4]/econ.lr$estimate[2] - econ.lr$estimate[3]/econ.lr$estimate[1]),
    lb = c(quantile(boot_ratios_r$ratio, 0.025),quantile(boot_ratios_d$ratio, 0.025), quantile(boot_diffs$ratio_diff, 0.025)),
    ub = c(quantile(boot_ratios_r$ratio, 0.975),quantile(boot_ratios_d$ratio, 0.975), quantile(boot_diffs$ratio_diff, 0.975))
  )%>%
    mutate(x = c(2,1,3))
  
  ggplot(ratio.df, aes(x = x, y = estimate, color = factor(x), shape = factor(x)))+
    geom_point(size=2)+
    geom_linerange(aes(ymax = ub, ymin = lb))+
    scale_x_continuous(breaks = c(1,2,3), limits = c(0.8,3.2),
                       labels = c("Democrats\nCongenial", "Republicans\nUncongenial", "Difference\n(Dem - Rep)"))+
    scale_color_manual(breaks = factor(1:3), values = c("navy", "red4", "black"))+
    scale_shape_manual(breaks = factor(1:3), values=c(16,17,1))+theme_bw()+
    labs(y = "Persistance Ratio")+
    geom_hline(yintercept = 0, linetype="dotted",size=0.5)+
    theme(panel.grid.major=element_blank(),
          panel.grid.minor=element_blank(),
          panel.border=element_rect(colour="black"),
          axis.title.x=element_blank(),
          legend.position = "none",
          legend.background = element_rect(fill="transparent"),
          plot.title = element_text(size=8,hjust=0.5),
          axis.title.y= element_text(size=7),
          axis.text.x = element_text(color = "black", size=6),
          axis.text.y = element_text(color = "black", size=7))
  ggsave("figs26.pdf",width=3.5,height=3)
  
  